nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.97k stars 394 forks source link

nest new: prebuild is not working during start:prod command #614

Closed jeffminsungkim closed 4 years ago

jeffminsungkim commented 4 years ago

I'm submitting a...


[x] Regression 
[ ] 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

When I hit the start:prod command, I get the following error message.

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

Error: Cannot find module '/Users/jeffminsungkim/projects/personal/reproduction/new-project/dist/main'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11
error Command failed with exit code 1.

Expected behavior

Nest CLI should either provide a prestart command for production or prebuild and build command needs to be executed beforehand.

"scripts": {
  "prebuild": "rimraf dist",
  "build": "nest build",
  "prestart:prod": "rimraf dist && npm run build",
  "start:prod": "node dist/main"
}

Minimal reproduction of the problem with instructions

Create a new project using Nest CLI.

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

Environment

[System Information]
OS Version     : macOS Catalina
NodeJS Version : v12.5.0
YARN Version    : 1.21.1

[Nest CLI]
Nest CLI Version : 7.0.2

[Nest Platform Information]
platform-express version : 7.0.0
common version           : 7.0.0
core version             : 7.0.0
kamilmysliwiec commented 4 years ago

https://github.com/nestjs/typescript-starter/issues/135

jeffminsungkim commented 4 years ago

@kamilmysliwiec Hi, Kami. I'm not sure why you closed the thread.

Since, typescript-starter and the nest new command use new CLI commands, it addresses the same issue that I've mentioned.

Can you start the project when you hit npm run start:prod from either the typescript-starter or the Nest CLI?

kamilmysliwiec commented 4 years ago

This has been discussed many times in the past already. There's no prebuild hook for start:prod. See old issues in typescript-starter repo