Nest: npm run start:prod => failed on very first try

Created on 21 Jan 2019  ยท  7Comments  ยท  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


npm run start:prod failed on fresh project

Expected behavior


It should run OK.

Minimal reproduction of the problem with instructions

$ npm i -g @nestjs/cli
$ nest new project-name
$ cd project-name
$ npm run start:prod

Opps! Error:

> [email protected] prestart:prod ~/project-name
> rimraf dist && tsc


> [email protected] start:prod ~/project-name
> node dist/main.js

internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module '~/project-name/dist/main.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start:prod: `node dist/main.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start:prod script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2019-01-21T02_30_39_812Z-debug.log

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.4.0


For Tooling issues:
- Node version: v10.9.0  
- npm: 6.2.0
- Platform:  Mac

Others:

Most helpful comment

Change your prestart:prod script to the following one:

"prestart:prod": "rimraf dist && npm run build"

All 7 comments

You need to build it first using tsc

Tried and got same error.

The problem is:
The result after built:

โ”œโ”€โ”€ src
โ”‚ย ย  โ”œโ”€โ”€ main.js
โ”‚ย ย  โ””โ”€โ”€ main.js.map
โ””โ”€โ”€ test
    โ”œโ”€โ”€ app.e2e-spec.d.ts
    โ”œโ”€โ”€ app.e2e-spec.js
    โ””โ”€โ”€ app.e2e-spec.js.map

While command in package.json is "start:prod": "node dist/main.js",

Change your prestart:prod script to the following one:

"prestart:prod": "rimraf dist && npm run build"

Same wrong

I got same issue when .ts files outside src and test directory.
It cames normal when I added that files to exclude in tsconfig.build.json.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdiaz picture cdiaz  ยท  3Comments

JulianBiermann picture JulianBiermann  ยท  3Comments

menme95 picture menme95  ยท  3Comments

mishelashala picture mishelashala  ยท  3Comments

cojack picture cojack  ยท  3Comments