I'm building an API based on Nestjs. The main.ts
file is nested in a subfolder of my src
directory. As a result, the compiled files are also nested in the dist
directory and my entry point is dist/api/main.js
instead of dist/main.js
. I would like to keep things that way.
When starting my app with npm run start:dev
, I get the following error:
4:47:32 PM - Found 0 errors. Watching for file changes.
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module '/home/ymonb/Nest.js/myProject/dist/main'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:17)
at Function.Module._load (internal/modules/cjs/loader.js:859:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
I need to be able to reconfigure Nest with the new path. I looked into the documentation, but I don't see anything to specify a different entry point.
I think that maybe I need to edit nest-cli.json
, but I can't find any documentation about the possible options in this file (if you know of such documentation, i'm interested!).
This is my nest-cli.json
:
{
"collection": "@nestjs/schematics",
"sourceRoot": "src/api"
}
Any idea?
You can edit nest-cli.json like this:
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"entryFile": "your/main/js/path"
}
and nest-cli will load: your/main/js/path.js
I found config in source code. nest-cli/lib/configuration/configuration.ts
Go to your "nest-cli.json" and edit the "entryFile" config.
It should be linked to the main.js file inside the "dist/main" file.
It should look like this :
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"entryFile": "copy the relative path of your main.js and paste it here"
}
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