Closed x2pdenjo closed 5 years ago
review package.json nodemon.json and reinstall global nodemon
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
.
We already moved typescript-starter
to nodemon
+ regular tsc
. Let's track schematics issue here https://github.com/nestjs/schematics/issues/172
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 .
Same here!
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 .
Any update here? I'm experiencing a similar problem.
Disregard my last comment. I removed the noEmit flag from tsconfig.json.. it fixed my problem.
Simply make the following changes to config files in order to get npm run start:dev
working again:
❌ "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\" ",
❌ "exec": "node dist/main"
✅ "exec": "node dist/src/main"
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?
I had the same problem. It occurred when my project root had 2 folders with .ts
files. For example, if I created the file foo/a.ts
then I ended up with dist/src
and dist/foo
. If I deleted the dist
and foo
folders and reran npm run start:dev
then everything was fine.
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"
This works for me. Thanks @id-kemo
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
For better developer experience, I have just updated both
typescript-starter
andschematics
(nest new
). From now (moving forward), we'll usetsc-watch
+ justnode
forstart:dev
andstart: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: nestjs/typescript-starter@7f2dde2
and remove
concurrently
andwait-on
from devDependencies
Hi Kamil,
My team and I are running into issues with this. We had a working project and are doing a rewrite and we used the Nest new project command, installed TypeORM, etc etc. and now when we use "npm run start" with "entities": [ "src/*/.entity{.ts,.js}"] our app works but with "npm run start:dev" it breaks. On the other hand when using "entities": [ "dist/*/.entity{.ts,.js}"] then start:dev works while start does not. We had a similar issue with our old project but our fix for that is not working either. Any help would be appreciated
@kamilmysliwiec I've created a new project a few days ago and have the same setup as after your commit. When I run npm run start:dev
I get the following error:
internal/modules/cjs/loader.js:584
throw err;
^
Error: Cannot find module 'C:\Users\Filip\Documents\Projects\hr-app\server\dist\main.js'
After checking, main.js
is not in dist but rather in dist/src.
Do you plan on updating the package.json script?
@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",
]
@bmoe24x why not use
"entities": [
join(__dirname, "/**/*.entity.ts")
]
So that it works with both dist and src without explicit dependencies?
@jmcdo29 because some people are using ormconfig.json
to load configuration
@kamilmysliwiec ah, good point. I guess it could be made into a js file, but otherwise your solution is better :smiley:
@filipjnc it means that you have some other directories (not only
src
) that contain TS files. You should update your paths then.
Genius. Didn't know ts builds the project in relation to that. I moved that knex config file into src, got rid of the old dist and then it worked. Thanks!
@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", ]
@kamilmysliwiec no luck with this in an ormconfig.json file. Works for 'npm run start' but not 'npm run start:dev' where we get the message "[TypeOrmModule] Unable to connect to the database. Retrying (1)"
Works for 'npm run start' but not 'npm run start:dev' where we get the message "[TypeOrmModule] Unable to connect to the database. Retrying (1)"
It's not related to "entities"
property.
Works for 'npm run start' but not 'npm run start:dev' where we get the message "[TypeOrmModule] Unable to connect to the database. Retrying (1)"
It's not related to
"entities"
property.
@kamilmysliwiec any idea what it is related to then? Changing that property is the only thing we have found to effect it so kind of struggling. It is annoying since our previous project worked with both 'npm run start' and 'npm run start:dev'
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\" ",
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
Guys try set your entities value like this:
entities: [path.join(__dirname, '../') + '/*/.entity{.ts,.js}'],
You may play with folder levels in path.join(__dirname, '../')
@TautvydasDerzinskas how is that going to fix the issue when it's the fact that TypeORM can't differentiate between file types when ran in dev mode or not? Did you see @ebadia 's post above?
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
@TautvydasDerzinskas how is that going to fix the issue when it's the fact that TypeORM can't differentiate between file types when ran in dev mode or not? Did you see @ebadia 's post above?
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
First of all you need to define both .entity.js and .entity.ts as in different start modes different kinds of files are being consumed.
Errors and issues mentioned by people (such as @ebadia ) in this discussion usually happen because entity files can't be resolved. Even though error messages can simply state "Unable to connect to the database...." which often is misleading.
I dealt with exact symptoms on one project myself, and using absolute paths resolved it!
entities: [path.join(__dirname, '../') + '/**/*.entity{.ts,.js}'],
Waiting for someone who is actually dealing with these problems to try it out.
I had the same issue and your solution did not work. yarn start:dev
tried loading both js and ts files and threw an error on the first ts file. The solution for me was to set the file extension based on an environment variable.
npm run start
and npm run start:dev
work with:
entities: [ path.join(__dirname, '../') + '**/*.entity.js' ]
nestjs verion 6.9.0
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.
I'm submitting a...
Current behavior
Sometimes, when I run e.g. npm run start:dev then Nest.js is not starting.
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.
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