nest: Nest app is not starting with npm run start (:dev)

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

Sometimes, when I run e.g. npm run start:dev then Nest.js is not starting.

[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: C:\Users\kvn\workspace\kargo\kargo-client-be\src/**/*
[nodemon] starting `ts-node -r tsconfig-paths/register src/main.ts`

That’s all what is coming for more than 10 minutes. I think it has something to do with performance and the scale of the project. My projects has around 30 modules.

I found a solution: I open my app.module.ts and comment almost every of my module, to make the app more lightweight. Then it runs again, and I remove every module step by step from comment block.

Module({
  providers,
  imports: [
    ConfigModule,
    MailModule,
    // ContactModule,
    // AuthModule,
    // CompanyModule,
    // AccountModule,
    // ProductModule,
  ],
  controllers: [AppController],
})
export class AppModule {}

Expected behavior

It should just start.

Minimal reproduction of the problem with instructions

I guess you can reproduce it with any bigger Nest.js project and a not so good PC/Notebook.

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

Well, people with less good PC/Notebooks can’t work on my project.

Environment


Nest version: 5.4.0

 
For Tooling issues:
- Node version: 10.14.1  
- Platform:  Win 10 64x Home, 16 GB RAM, i7 6 Generation

Others:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 31 (8 by maintainers)

Most upvoted comments

Simply make the following changes to config files in order to get npm run start:dev working again:

package.json

"start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ", "start:dev": "concurrently --handle-input \"wait-on dist/src/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",

nodemon.json

"exec": "node dist/main""exec": "node dist/src/main"

image

I am facing same issue , after created project using nest-cli . After I “npm run start:dev” , my terminal just show : Starting compilation in watch mode … just it , no other [nodemon] or [Nest] related message .

That’s what I observed in my typeorm config:

  • if i write [“src/**/*.entity.ts”] in entities then npm run start works, but not npm run start:dev (Unable to connect to the database. SyntaxError: Unexpected token { … )

  • if i write [“dist/**/*.entity.js”] in entities then npm run start:dev works, but not npm run start (RepositoryNotFoundError)

  • if i write [“src//*.entity.ts", "dist//*.entity.js”] in entities then npm run start works, but not npm run start:dev (Unable to connect to the database. SyntaxError: Unexpected token { … )

I could not make it work for both “starts” with only one configuration

That’s what I observed in my typeorm config:

  • if i write [“src/**/*.entity.ts”] in entities then npm run start works, but not npm run start:dev (Unable to connect to the database. SyntaxError: Unexpected token { … )
  • if i write [“dist/**/*.entity.js”] in entities then npm run start:dev works, but not npm run start (RepositoryNotFoundError)
  • if i write [“src//*.entity.ts", "dist//*.entity.js”] in entities then npm run start works, but not npm run start:dev (Unable to connect to the database. SyntaxError: Unexpected token { … )

I could not make it work for both “starts” with only one configuration

@kamilmysliwiec could we reopen this or could you point us to somewhere that more closely relates to this issue? It seems that it is not an isolated issue

@filipjnc it means that you have some other directories (not only src) that contain TS files. You should update your paths then.

@bmoe24x what about this:

"entities": [
   "src//*.entity.ts",
   "dist//*.entity.js",
]

For better developer experience, I have just updated both typescript-starter and schematics (nest new). From now (moving forward), we’ll use tsc-watch + just node for start:dev and start:debug - no concurrently and wait-on dependencies. Hence, we should get more descriptive errors (not jus empty console) 😃

If you want to migrate your existing apps, follow this commit: https://github.com/nestjs/typescript-starter/commit/7f2dde2d6c5335306ec559195fb0e634edd5c314

and remove concurrently and wait-on from devDependencies

Has anyone fix that? I have the same issue.

“Unable to connect to the database. Retrying (1)”

Tested on scripts: “start:dev”: “tsc-watch -p tsconfig.build.json --onSuccess "node dist/main.js"”, and older: “start:dev”: "concurrently --handle-input "wait-on dist/main.js && nodemon" "tsc -w -p tsconfig.build.json" ",

All of a sudden this recently happened in my nest codebase. The approach from @id-kemo worked, my concern is why did this all of a sudden change from compiling to dist/main.js to dist/src/main.js? Was there an underlying dependency change that triggered it?

Same here!

One option is to remove nodemon and ts-node and switch it out for tsc (regular typescript compiler) or tsc-watch (typescript compiler package in watch mode). The problem with ts-node is that it will run out of memory and have problems keeping your app running, hence why you should opt to run your app with node instead of ts-node. ts-node is a great dev tool, but I’ve had my issues with it over time and eventually opted for tsc-watch instead. It all comes down to dev preference though.

See my response here for a little bit more in depth of an answer about tsc-watch.