I'm trying to use ts-transformation-keys in my Nest application.
I started a new application using a template from this repository, and my machine is running with windows 10.
As described in the ts-transformation-keys documentation, i added the following configuration in the tsconfig.json file:
{
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"target": "ES2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"plugins": [
{ "transform": "ts-transformer-keys/transformer" },
]
},
"exclude": [
"node_modules",
"dist",
"graphql",
"onboard"
]
}
That's my package.json file:
{
"name": "nestjs-prisma-client-starter",
"version": "0.0.1",
"description": "NestJS Prisma Client Starter Project",
"author": "Marc Stammerjohann",
"license": "MIT",
"keywords": [
"NestJS",
"Prisma",
"Prisma Client",
"Typescript"
],
"repository": {
"type": "git",
"url": "https://github.com/fivethree-team/nestjs-prisma-client-example.git"
},
"bugs": {
"url": "https://github.com/fivethree-team/nestjs-prisma-client-example/issues"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"migrate:dev": "prisma migrate dev --preview-feature",
"migrate:dev:create": "prisma migrate dev --create-only --preview-feature",
"migrate:reset": "prisma migrate reset --preview-feature",
"migrate:deploy": "npx prisma migrate deploy --preview-feature",
"migrate:status": "npx prisma migrate status --preview-feature",
"migrate:resolve": "npx prisma migrate resolve --preview-feature",
"prisma:studio": "npx prisma studio",
"prisma:generate": "npx prisma generate",
"prisma:generate:watch": "npx prisma generate --watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"start:db": "npm run migrate:up && npm run prisma:generate && npm run seed",
"seed": "ts-node prisma/seed.ts",
"postinstall": "npm run prisma:generate",
"docker:migrate": "docker-compose -f docker-compose.migrate.yml up -d",
"docker:db": "docker-compose -f docker-compose.db.yml up -d",
"docker:seed": "docker exec -it nest-api npm run seed",
"docker": "docker-compose up -d",
"docker:build": "docker-compose build"
},
"dependencies": {
"#devoxa/prisma-relay-cursor-connection": "1.1.1",
"#nestjs/common": "7.6.15",
"#nestjs/config": "0.6.3",
"#nestjs/core": "7.6.15",
"#nestjs/graphql": "7.10.3",
"#nestjs/jwt": "7.2.0",
"#nestjs/passport": "7.1.5",
"#nestjs/platform-express": "7.6.15",
"#nestjs/swagger": "4.8.0",
"#prisma/client": "2.20.1",
"apollo-server-express": "2.22.2",
"bcrypt": "5.0.1",
"class-transformer": "0.4.0",
"class-validator": "0.13.1",
"dayjs": "^1.10.4",
"graphql": "15.5.0",
"graphql-tools": "7.0.4",
"linq-es2015": "^2.5.1",
"parcel-plugin-ttypescript": "^1.0.2",
"passport": "0.4.1",
"passport-jwt": "4.0.0",
"reflect-metadata": "0.1.13",
"rxjs": "6.6.7",
"swagger-ui-express": "4.1.6"
},
"devDependencies": {
"#apollo/gateway": "0.26.0",
"#nestjs/cli": "7.6.0",
"#nestjs/testing": "7.6.15",
"#types/bcrypt": "3.0.0",
"#types/chance": "1.1.1",
"#types/express": "4.17.11",
"#types/jest": "26.0.22",
"#types/node": "14.14.37",
"#types/supertest": "^2.0.11",
"#typescript-eslint/eslint-plugin": "4.21.0",
"#typescript-eslint/parser": "4.21.0",
"chance": "1.1.7",
"eslint": "7.23.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-prettier": "3.3.1",
"jest": "26.6.3",
"prettier": "2.2.1",
"prisma": "2.20.1",
"prisma-dbml-generator": "0.5.0",
"rimraf": "3.0.2",
"supertest": "6.1.3",
"ts-jest": "26.5.4",
"ts-loader": "8.1.0",
"ts-node": "9.1.1",
"ts-transformer-keys": "^0.4.3",
"tsconfig-paths": "3.9.0",
"ttypescript": "^1.5.12",
"typescript": "^4.2.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
So, here's the problem:
i already ran these scripts:
npm i -g #nestjs/cli
npm install
npm build
npm start:debug
All these things worked well... But when i'm trying to use the ts-transformation-keys it doesn't work.
I added this small piece of code in the src/app.module.ts:
class myTestClass
{
id : string;
name : string;
}
let test = keys<myTestClass>()
Then i got this error:
TypeError: ts_transformer_keys_1.keys is not a function
at Object.<anonymous> (C:\Repos\EDM\backend\dist\app.module.js:26:34)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Repos\EDM\backend\dist\main.js:7:22)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
It's generating this javascript code:
[...]
const ts_transformer_keys_1 = require("ts-transformer-keys");
class myTestClass {
}
let test = ts_transformer_keys_1.keys();
[...]
Does anyone know what is wrong in my configuration?
I already tried to use different versions of ts-transformation-keys, but looks like Nest is not loading the custom transform described in tsconfig.json file.
Related
I am creating a dependancy to generate PDF on nestjs, to do it I am using puppeteer.
When I try to use puppeteer inside the dependancy I get an error:
Error: Run `npm install` to download the correct Chromium revision (1056772).
But when I do it from the project and not the dependancy there is no error. It only happen when I use puppeteer from the dependancy, but it's launched from the same project.
First I generated the PDF inside a nestjs project and it worked fine.
Then I moved the code to my library inside a service but then there is the error.
I tried to run the following command to install chromium
node node_modules/puppeteer/install.js
But nothing change and here is the result of the command:
Chromium is already in C:\Users\Greg.cache\puppeteer\chrome\win64-1069273; skipping download.
I also tried to delete the node modules and reinstall it but no change.
The package.json of the dependancy:
{
"name": "#gboutte/nestjs-pdf",
"version": "0.0.3",
"description": "This package provide a service to render PDF from html string or from handlebars tempaltes for nestjs.",
"keywords": [
"nestjs",
"handlebars",
"hbs",
"templates",
"pdf"
],
"homepage": "https://github.com/gboutte/nestjs-pdf#readme",
"bugs": {
"url": "https://github.com/gboutte/nestjs-pdf/issues",
"email": "gboutte#protonmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/gboutte/nestjs-pdf"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rimraf dist && tsc",
"prepublish": "npm run build"
},
"author": "Grégory Boutte <gboutte#protonmail.com>",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"#nestjs/common": "^9.1.6",
"#gboutte/nestjs-hbs": "^0.0.3",
"#types/node": "^18.11.5",
"puppeteer": "^19.1.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.7",
"typescript": "^4.8.4"
},
"peerDependencies": {
"#nestjs/common": "^9.1.6",
"#gboutte/nestjs-hbs": "^0.0.3",
"#types/node": "^18.11.5",
"puppeteer": "^19.1.2",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.7",
"typescript": "^4.8.4"
}
}
And the package.json of the main project
{
"name": "nestjs-hbs-demo",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"main": "dist/index.js",
"readmeFilename": "README.md",
"files": [
"dist/**/*",
"*.md"
],
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#gboutte/nestjs-hbs": "file:../nestjs-hbs",
"#gboutte/nestjs-pdf": "file:../nestjs-pdf",
"#nestjs/common": "^9.0.0",
"#nestjs/core": "^9.0.0",
"#nestjs/platform-express": "^9.0.0",
"#nestjs/platform-fastify": "^9.1.6",
"puppeteer": "^19.4.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"#nestjs/cli": "^9.0.0",
"#nestjs/schematics": "^9.0.0",
"#nestjs/testing": "^9.0.0",
"#types/express": "^4.17.13",
"#types/jest": "28.1.8",
"#types/node": "^16.0.0",
"#types/supertest": "^2.0.11",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"#typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
I resolved the issue by updating my local nodejs and I changed the #types/node dependency of both project to be the same.
"#types/node": "^18.0.0",
I found out that it was this problem by trying to install the library with github instead of locally.
Before I used npm install ../directory-to-my-lib, then I used npm install <url to the github repo>.
The difference is that using github npm gave me an error saying that both version of #types/node were different, I don't know why I did not have this error using the other command.
Now that I fixed the version it works with all installation methods (npm package / github / locally).
I'm following the NestJS documentation on how to set up a fastify/apollo server with nest but after adding fastify to main.ts I get this error:
FastifyError: fastify-plugin: fastify-accepts - expected '3.x' fastify version, '4.6.0' is installed
I've tried installing fastify 3.x, changing versions of other modules but according to yarn.lock some modules need 3.x and others need 4.x.
These are the docs I'm following:
https://docs.nestjs.com/techniques/performance
https://docs.nestjs.com/graphql/quick-start
Here is my main.ts
import { NestFactory } from '#nestjs/core';
import { AppModule } from './app.module';
import {
FastifyAdapter,
NestFastifyApplication,
} from '#nestjs/platform-fastify';
import { ValidationPipe } from '#nestjs/common';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({ logger: true }),
);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();
Here is my package.json
{
"name": "app",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#nestjs/apollo": "^10.1.0",
"#nestjs/common": "^9.0.0",
"#nestjs/core": "^9.0.0",
"#nestjs/graphql": "^10.1.2",
"#nestjs/platform-express": "^9.0.0",
"#nestjs/platform-fastify": "^9.1.1",
"apollo-server-fastify": "^3.10.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"firebase-admin": "^11.0.1",
"graphql": "^16.6.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"ts-morph": "^16.0.0"
},
"devDependencies": {
"#nestjs/cli": "^9.0.0",
"#nestjs/schematics": "^9.0.0",
"#nestjs/testing": "^9.0.0",
"#types/express": "^4.17.13",
"#types/jest": "28.1.8",
"#types/node": "^16.0.0",
"#types/supertest": "^2.0.11",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"#typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
#nestjs/common#^9 and #nestjs/platform-fastify#^9 require you to use fastify#^4. However, apllo-server-fastify does not support fastify#^4 and will not until apollo-server v4 comes out. Until then,. you can follow the docs and use mercurius instead.
Your other option would be to downgrade to #nestjs/common#^8 and #nestjs/platform-fastify#^8 along with #nestjs/graphql#^9 which supports fastify#^3
I don't know what happened but I'm not being able to run a NestJS application locally
What I've tried so far:
deleting node_modules
deleting package-lock.json
npm i --save-dev #types/node
gave up and git cloned the whole application in a different folder (that runs on my colleagues' machines but not mine, they couldn't figure it out either)
I've been losing my mind, any help is appreciated
NPM Version 8.5.4
Node.js Version v16.14.2
tsconfig.json:
{
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"target": "es2020",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src/",
"paths": {
"<rootDir>/": ["."]
},
"incremental": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true
}
}
tsconfig.build.json:
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "__mocks__", "dist", "**/*spec.ts"]
}
package.json:
{
"name": "REDACTED",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"check-env": "node -r ts-node/register -r tsconfig-paths/register src/checkEnvs.ts",
"prebuild": "rimraf dist && npm run check-env",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node --max-old-space-size=2500 dist/src/main.js",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --detectOpenHandles",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:noCov": "jest --watch --collectCoverage=false",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"prisma:create": "npx prisma migrate dev --create-only",
"prisma:run": "npx prisma migrate dev",
"prisma:generate": "npx prisma generate"
},
"dependencies": {
"#elastic/elasticsearch": "7.10",
"#nestjs/bull": "^0.4.2",
"#nestjs/common": "^8.0.0",
"#nestjs/config": "^1.1.0",
"#nestjs/core": "^8.0.0",
"#nestjs/elasticsearch": "^8.0.0",
"#nestjs/event-emitter": "^1.0.0",
"#nestjs/microservices": "^8.1.2",
"#nestjs/mongoose": "^9.0.3",
"#nestjs/platform-express": "^8.4.4",
"#nestjs/schedule": "^1.1.0",
"#ntegral/nestjs-sentry": "^3.0.7",
"#prisma/client": "^3.14.0",
"#sentry/node": "^6.17.3",
"#sentry/types": "^6.17.3",
"amqp-connection-manager": "^3.7.0",
"amqplib": "^0.8.0",
"axios": "^0.24.0",
"bull": "^3.29.3",
"class-validator": "^0.13.2",
"cli-progress": "^3.10.0",
"date-fns": "^2.27.0",
"fast-csv": "^4.3.6",
"lodash": "^4.17.21",
"mongoose": "^6.2.10",
"nestjs-ftp": "^0.1.13",
"nestjs-soap": "^2.0.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"xml-js": "^1.6.11"
},
"devDependencies": {
"#golevelup/ts-jest": "^0.3.2",
"#nestjs/cli": "^8.0.0",
"#nestjs/schematics": "^8.0.0",
"#nestjs/testing": "^8.0.0",
"#types/bull": "^3.15.7",
"#types/cli-progress": "^3.9.2",
"#types/cron": "^1.7.3",
"#types/express": "^4.17.13",
"#types/jest": "^27.0.1",
"#types/lodash": "^4.14.179",
"#types/node": "^16.0.0",
"#types/sax": "^1.2.3",
"#types/supertest": "^2.0.11",
"#types/validator": "^13.7.2",
"#typescript-eslint/eslint-plugin": "^4.28.2",
"#typescript-eslint/parser": "^4.28.2",
"eslint": "^7.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"leaked-handles": "^5.2.0",
"mongodb-memory-server": "^8.4.2",
"prettier": "^2.3.2",
"prisma": "^3.14.0",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
}
}
If someone finds this question pulling their hair out, it turned out to have been my tsconfig.json file, all I had to do was roll back the lib version from "lib": ["es2020"] to "lib": ["es2017"],
I wish I had seen that on my crystal ball
npm run start works fine, but npm run start: dev throws this error:
7:14:22 PM - Found 0 errors. Watching for file changes.
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'src/models/note.model'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Anuitex-169\Desktop\VersF\nest\server\dist\note\note.service.js:17:22)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
This error appeared from the very beginning of my project, and I can’t understand why. I decided to forget about this problem since npm run start works well. But somehow uncomfortable (
My app.module.ts
My package.json file:
{
"name": "server",
"version": "0.0.1",
"description": "",
"author": "",
"license": "MIT",
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "tsc-watch -p tsconfig.build.json --onSuccess \"node dist/main.js\"",
"start:debug": "tsc-watch -p tsconfig.build.json --onSuccess \"node --inspect-brk dist/main.js\"",
"start:prod": "node dist/main.js",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#nestjs/common": "^6.0.0",
"#nestjs/core": "^6.0.0",
"#nestjs/platform-express": "^6.0.0",
"#nestjs/typeorm": "^6.1.3",
"mongodb": "^3.3.2",
"path": "^0.12.7",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3",
"typeorm": "^0.2.19"
},
"devDependencies": {
"#nestjs/testing": "^6.0.0",
"#types/express": "4.16.1",
"#types/jest": "24.0.11",
"#types/multer": "^1.3.10",
"#types/node": "11.13.4",
"#types/supertest": "2.0.7",
"jest": "24.7.1",
"prettier": "1.17.0",
"supertest": "4.0.2",
"ts-jest": "24.0.2",
"ts-node": "8.1.0",
"tsc-watch": "2.2.1",
"tsconfig-paths": "3.8.0",
"tslint": "5.16.0",
"typescript": "3.4.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": ".",
"roots": [
"<rootDir>/src/",
"<rootDir>/libs/",
"<rootDir>/apps/"
],
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "./coverage",
"testEnvironment": "node"
}
}
Please help me deal with this problem.
Your AppModule looks fine, so I have to wonder if something is happening in your NoteService, which this line makes it looks like that is the case at Object.<anonymous> (C:\Users\Anuitex-169\Desktop\VersF\nest\server\dist\note\note.service.js:17:22).
If I had to bet, you are trying to read the module from your src directory while you are in your dist directory (at least by standard Typescript compilation). Instead of using an import like src/models/note.model you should use an import that takes into account the path from the current file (such as ../models/note.model). You may need to change that a bit more, but that's the idea of what should happen
I have followed the tutorial for nestJs and have a basic working app. After that, I tried the tutorial to connect my app with webpack and hotreloading and am now presented with the following error:
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:703:23)
I have tried looking at similar errors and cannot find anything conclusive other than hints here and there to something that is not compiling in my test files - any direction would be greatly appreciated.
Using Node 12, npm 6.9.0
Package JSON below:
"scripts": {
"build": "tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node dist/server",
"webpack": "webpack --config webpack.config.js",
"start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && npm run build",
"start:prod": "node dist/main.js",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"#nestjs/common": "^6.0.4",
"#nestjs/core": "^6.0.4",
"#nestjs/microservices": "^6.0.4",
"#nestjs/platform-express": "^6.0.4",
"#nestjs/swagger": "^3.0.2",
"#nestjs/typeorm": "^6.1.1",
"#nestjs/websockets": "^6.0.4",
"mysql": "^2.17.1",
"reflect-metadata": "0.1.13",
"rimraf": "2.6.3",
"rxjs": "6.4.0",
"swagger-ui-express": "^4.0.4",
"typeorm": "^0.2.17"
},
"devDependencies": {
"#nestjs/testing": "6.1.1",
"#types/express": "^4.16.1",
"#types/jest": "24.0.11",
"#types/node": "11.13.4",
"#types/supertest": "2.0.7",
"concurrently": "^4.1.0",
"jest": "24.7.1",
"nodemon": "1.18.11",
"prettier": "1.17.0",
"supertest": "4.0.2",
"ts-jest": "24.0.2",
"ts-loader": "^6.0.1",
"ts-node": "8.1.0",
"tsconfig-paths": "3.8.0",
"tslint": "5.16.0",
"typescript": "3.4.3",
"wait-on": "^3.2.0",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2",
"webpack-node-externals": "^1.7.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
this is probably the tsconfig, are you using:
"module": "commonjs" In the compilerOptions ? When you working with nodejs this is the option that you have to use
I finally posted this on NestJS repo and received a response for those interested:
https://github.com/nestjs/nest/issues/2389