I tried to start my project with npm run start:prod
command but got
Error: Cannot find module {path to my project}\dist\main.js'
.
I have tried to rename the path to all my files in the project from src/myController to ../myController .
My package.json (scripts)
"scripts": {
"build": "tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "concurrently \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.json\" ",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && npm run build",
"start:prod": "node dist/main.js"
My tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"rootDir": ".",
"outDir": "../dist",
"baseUrl": "./src"
},
"include": [ "./src/**/*.ts", ],
"exclude": ["node_modules", "dist", "src/**/*.spec.ts", "src/**/__test__/*"]
}
The actual output:
[email protected] prestart:prod {path to my project} rimraf dist && npm run build
[email protected] build {path to my project} tsc -p tsconfig.build.json
[email protected] start:prod {path to my project} node dist/main.js
internal/modules/cjs/loader.js:584 throw err; ^
Error: Cannot find module {path to my project}\dist\main.js'
Okeey, I was a little dumb. The answer is very easy. In package.json you need change line from "start:prod": "node dist/main.js"
to "start:prod": "node dist/src/main.js"
. In tsconfig.json you need change "outDir": "../dist"
to "outDir": "./dist"
you can just add a new command: under the scripts in package.json :
"start:live": "rimraf dist && nest build && node dist/src/main",
then you can run:
npm run start:live
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With