Nest doesnt want to compile dist correctly
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Current behavior
Nest does not compile the dist folder correctly. I first encountered this problem when nest stopped updating my code, after a few hours I opened the dist folder:
dist
config
server/src <- here are app module and auth module
tsconfig.build.tsbuildinfo
when I run npm run start or npm run start:dev I get an error:
Error: Cannot find module 'C:\Users\server\dist\main'
at Function.Module._resolveFilename(node: internal/modules/cjs/loader:933:15)
in Function.Module._load(node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain](node:internal/modules/run_main:81:12)
on node: internal/main/run_main_module:17:47
and it’s true, main is in the dist/server/src folder which has been compiled into three files main.d.ts, main.js, main.js.map but I don’t understand why the root folder of the server is duplicated and files without the root folder are not compiled (for example, just dist/main)
before that all i saw was that nest didn’t want to update my files, then i removed dist, ran npm run build to update my code but no success, nest created server folder (why?), and after that when i ran start i had the same error
Minimum reproduction code
https://github.com/lohevol/nestjs-issue/
Steps to reproduce
npm run start:dev- try to update anything
- see what nothing doesnt update or
npm run start:dev- delete dist (what i did when code stopped to update)
npm run build(i thought it can help to update)npm run start:dev- See error
Expected behavior
what nest compile files without server folder, just dist/main, dist/app.module, etc.
Package
- I don’t know. Or some 3rd-party package
-
@nestjs/common -
@nestjs/core -
@nestjs/microservices -
@nestjs/platform-express -
@nestjs/platform-fastify -
@nestjs/platform-socket.io -
@nestjs/platform-ws -
@nestjs/testing -
@nestjs/websockets - Other (see below)
Other package
no
NestJS version
8.0.0
Packages versions
{
"name": "server",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/mongoose": "^9.0.2",
"@nestjs/platform-express": "^8.0.0",
"bcryptjs": "^2.4.3",
"class-validator": "^0.13.2",
"mongoose": "^6.2.4",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
"@types/express": "^4.17.13",
"@types/jest": "27.4.1",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"jest": "^27.2.5",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
Node.js version
16.13.2
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Related StackOverflow Question
yes, it’s true, I forgot to add the config (which is out of src folder) folder to the repository, from which I import the configuration file… after deleting the import, everything worked, but how can I use the config now?
edit now I moved config folder into server, and now ts is working and compiling all correctly thank you
@lohevol read this: https://www.typescriptlang.org/tsconfig/rootDir.html and this: https://www.typescriptlang.org/tsconfig#baseUrl