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
Related
the node sass has a compatible problem with the Apple M1, this is the error when I build the project in M1:
[./node_modules/css-loader/dist/cjs.js?!./node_modules/postcss-loader/src/index.js?!./node_modules/sass-loader/dist/cjs.js!./src/css/options.scss] ./node_modules/css-loader/dist/cjs.js??ref--4-2!./node_modules/postcss-loader/src??ref--4-3!./node_modules/sass-loader/dist/cjs.js!./src/css/options.scss 1.54 KiB {mini-css-extract-plugin} [built] [failed] [1 error]
ERROR in ./src/css/options.scss (./node_modules/css-loader/dist/cjs.js??ref--4-2!./node_modules/postcss-loader/src??ref--4-3!./node_modules/sass-loader/dist/cjs.js!./src/css/options.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
Error: Node Sass does not yet support your current environment: OS X Unsupported architecture (arm64) with Unsupported runtime (93)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
at module.exports (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/node-sass/lib/binding.js:13:13)
at Object.<anonymous> (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/node-sass/lib/index.js:14:35)
at Module._compile (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/v8-compile-cache/v8-compile-cache.js:194:30)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at getDefaultSassImplementation (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/sass-loader/dist/utils.js:43:10)
at getSassImplementation (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/sass-loader/dist/utils.js:57:30)
at Object.loader (/Users/xiaoqiangjiang/source/reddwarf/frontend/Cruise-Radar/node_modules/sass-loader/dist/index.js:34:59)
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I have check my package.json and found I did not use node sass, just use less, this is the less version:
"less": "3.12.2",
what should I do to fix this problem? I have downgrade from node 17 to 16. BTW, this is the package.json:
{
"name": "cruise-radar",
"version": "0.0.1",
"description": "Browser extension to detect available RSS and RSSHub for current page",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack -w --mode=development --progress --display-error-details --colors",
"build": "webpack --mode=development --progress --display-error-details --colors",
"release": "npm run build && zip -r release/radar.zip dist",
"format": "eslint \"**/*.js\" --fix && prettier \"**/*.{js,scss,less}\" --write",
"format:staged": "eslint \"**/*.js\" --fix && pretty-quick --staged --verbose --pattern \"**/*.{js,scss,less}\"",
"format:check": "eslint \"**/*.js\" && prettier-check \"**/*.{js,scss,less}\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/jiangxiaoqiang/Cruise-Radar.git"
},
"keywords": [
"rsshub",
"rss"
],
"gitHooks": {
"pre-commit": "npm run format:staged"
},
"author": "DIYgod",
"license": "MIT",
"bugs": {
"url": "https://github.com/DIYgod/RSSHub-Radar/issues"
},
"homepage": "https://github.com/DIYgod/RSSHub-Radar#readme",
"devDependencies": {
"#babel/core": "7.12.3",
"#babel/preset-env": "7.12.1",
"#fingerprintjs/fingerprintjs": "3.1.2",
"autoprefixer": "9.8.6",
"babel-loader": "8.1.0",
"babel-plugin-component": "1.1.1",
"copy-webpack-plugin": "6.3.0",
"css-loader": "5.0.1",
"cssnano": "4.1.10",
"eslint": "7.13.0",
"eslint-config-prettier": "6.15.0",
"eslint-loader": "4.0.2",
"eslint-plugin-prettier": "3.1.4",
"file-loader": "6.2.0",
"less": "3.12.2",
"less-loader": "7.0.2",
"mini-css-extract-plugin": "1.3.0",
"postcss-loader": "3.0.0",
"prettier": "2.1.2",
"prettier-check": "2.0.0",
"pretty-quick": "3.1.0",
"sass-loader": "^10",
"svg-inline-loader": "0.8.2",
"template-string-optimize-loader": "3.0.0",
"url-loader": "4.1.1",
"vue": "2.6.12",
"vue-loader": "15.9.5",
"vue-template-compiler": "2.6.12",
"webpack": "4.44.2",
"webpack-cli": "3.3.12",
"yorkie": "2.0.0"
},
"dependencies": {
"clipboard": "2.0.6",
"element-ui": "2.14.0",
"md5.js": "^1.3.5",
"psl": "1.8.0",
"route-recognizer": "0.3.4",
"rss-parser": "3.9.0",
"vue-router": "3.4.9",
"yarn": "^1.22.17"
}
}
I'm trying to deploy my app on Heroku, having 2 package.json files.
First is for the frontend:
{
"name": "quiz",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "npm start --prefix server",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"heroku-postbuild": "npm run build --prefix server && ng build --prod"
},
"private": true,
"dependencies": {
"#angular/animations": "~12.0.2",
"#angular/common": "~12.0.2",
"#angular/compiler": "~12.0.2",
"#angular/core": "~12.0.2",
"#angular/forms": "~12.0.2",
"#angular/platform-browser": "~12.0.2",
"#angular/platform-browser-dynamic": "~12.0.2",
"#angular/router": "~12.0.2",
"rxjs": "~6.6.0",
"tslib": "^2.1.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#types/express": "^4.17.13",
"#angular-devkit/build-angular": "~12.0.2",
"#angular/cli": "~12.0.2",
"#angular/compiler-cli": "~12.0.2",
"#types/jasmine": "~3.6.0",
"#types/node": "^12.11.1",
"jasmine-core": "~3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.7.0",
"typescript": "~4.2.3"
},
"engines": {
"node": "16.x",
"npm": "7.x"
}
}
Second is for the backend:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "dist/index",
"scripts": {
"start": "node ./dist/server/index.js",
"dev": "nodemon index.ts",
"build": "tsc -p ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"#types/express": "^4.17.13",
"#types/node": "^16.6.1",
"nodemon": "^2.0.12",
"ts-node": "^10.2.1",
"typescript": "^4.3.5"
},
"dependencies": {
"express": "^4.17.1",
"zone.js": "^0.11.4"
},
"engines": {
"node": "16.x",
"npm": "7.x"
}
}
As my package.json starts first and triggers /server/package.json - first I try to build backend, using "heroku-postbuild" command in main package.json file and after that this command builds Angular app.
But after Heroku runs "start" command it shows such mistake:
Error: Cannot find module 'express'
2021-09-18T17:16:28.140193+00:00 app[web.1]: Require stack:
2021-09-18T17:16:28.140194+00:00 app[web.1]: - /app/server/dist/server/config/express.js
2021-09-18T17:16:28.140194+00:00 app[web.1]: - /app/server/dist/server/index.js
2021-09-18T17:16:28.140199+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2021-09-18T17:16:28.140200+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2021-09-18T17:16:28.140200+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2021-09-18T17:16:28.140200+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:94:18)
2021-09-18T17:16:28.140201+00:00 app[web.1]: at Object.<anonymous> (/app/server/dist/server/config/express.js:6:33)
2021-09-18T17:16:28.140201+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1101:14)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2021-09-18T17:16:28.140202+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2021-09-18T17:16:28.140203+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2021-09-18T17:16:28.140204+00:00 app[web.1]: requireStack: [
2021-09-18T17:16:28.140204+00:00 app[web.1]: '/app/server/dist/server/config/express.js',
2021-09-18T17:16:28.140204+00:00 app[web.1]: '/app/server/dist/server/index.js'
2021-09-18T17:16:28.140205+00:00 app[web.1]: ]
2021-09-18T17:16:28.140205+00:00 app[web.1]: }
When I run all those commands locally - it works.
I solved that problem by moving "express" into my main package.json file, but that's not what I'm trying to achieve. I want to have 2 separate json files so I can handle my installed modules for each backend and frontend easily.
What am I doing wrong?
So the problem was actually that I needed to do npm install both in server and frontend folders.
Heroku has a special command 'heroku-prebuild' which helps to prepare every folder to be built.
I created such commands:
"heroku-prebuild": "npm install --prefix server && npm install",
"heroku-postbuild": "npm run build --prefix server && ng build --prod"
Firstly, Heroku runs "heroku-prebuild", which installs all npm modules for both frontend and backend and, after that, it runs "heroku-postbuild", which builds frontend and backend dist folders.
After that it runs "start": "npm start --prefix server" and everything works.
I'm trying to run the command "npx react-native start" and shows this error
error Cannot find module '#expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\bin.js
Error: Cannot find module '#expo/metro-config'
Require stack:
- D:\Projetos\apporto\metro.config.js
- D:\Projetos\apporto\node_modules\cosmiconfig\node_modules\import-fresh\index.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\loaders.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\createExplorer.js
- D:\Projetos\apporto\node_modules\cosmiconfig\dist\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\tools\config\readConfigFromDisk.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\tools\config\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\commands\install\install.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\commands\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\index.js
- D:\Projetos\apporto\node_modules\#react-native-community\cli\build\bin.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (D:\Projetos\apporto\metro.config.js:1:30)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19)
I try to use the npm i metro-config --save-dev but doesn't work.
I don't know what to do.
#################### package.json ###############################
{
"name": "apporto",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/async-storage": "^1.12.1",
"#react-native-community/geolocation": "^2.0.2",
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/bottom-tabs": "^5.11.9",
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.4",
"react": "17.0.1",
"react-native": "0.64.0",
"react-native-gesture-handler": "^1.10.3",
"react-native-permissions": "^3.0.1",
"react-native-reanimated": "^2.1.0",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.1.1",
"react-native-svg": "*",
"react-native-svg-transformer": "^0.14.3",
"react-native-swiper": "^1.6.0",
"styled-components": "^5.2.3"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#babel/runtime": "^7.12.5",
"#react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-config": "^0.64.0",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
}
}
After installing expo/metro-config:
npm i #expo/metro-config
Go to metro.config.js change:
const { getDefaultConfig } = require('expo/metro-config');
To:
const { getDefaultConfig } = require('#expo/metro-config');
It works for me.
Thanks
The expo config file has been missing from here.
Run
npm i #expo/metro-config
In the main folder update the
metro.config.js
Change the following line
const { getDefaultConfig } = require('expo/metro-config');
to
const { getDefaultConfig } = require('#expo/metro-config');
Works like a Charm!
I had the same issue, I downloaded expo metro config and that fixed the issue
npm i #expo/metro-config
{
"name": "metro-config",
"version": "0.64.0",
"description": "🚇 Config parser for Metro.",
"main": "src/index.js",
"repository": {
"type": "git",
"url": "git#github.com:facebook/metro.git"
},
"scripts": {
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
},
"license": "MIT",
"dependencies": {
"cosmiconfig": "^5.0.5",
"jest-validate": "^26.5.2",
"metro": "0.64.0",
"metro-cache": "0.64.0",
"metro-core": "0.64.0",
"metro-runtime": "0.64.0"
},
"devDependencies": {
"pretty-format": "^26.5.2",
"strip-ansi": "^6.0.0"
}
}
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.
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