Closed lohevol closed 2 years ago
your repo didn't reproduce the issue
I got this after running npm run start:dev
src/app.module.ts:5:24 - error TS2307: Cannot find module '../../config/default' or its corresponding type declarations.
import { config } from '../../config/default';
Also,
what if you change that sourceRoot
to "src"
(which is the default when bootstraping a new app)
EDIT
You might need to adjust your tsconfig.json
to fulfill your needs. nest build
will use tsc
(typescript compiler) to build the project.
your repo didn't reproduce the issue
I got this after running
npm run start:dev
src/app.module.ts:5:24 - error TS2307: Cannot find module '../../config/default' or its corresponding type declarations. import { config } from '../../config/default';
Also,
what if you change that
sourceRoot
to"src"
(which is the default when bootstraping a new app)EDIT
You might need to adjust your
tsconfig.json
to fulfill your needs.nest build
will usetsc
(typescript compiler) to build the project.
I said that if the error is not reproduced, error occurred with bundle, then all files are still generated nested, and nest cannot access main, as well as new files, so nest did not react to the fact that I rewrote the code and issued the same thing, even if I could erase one file under a clean one, dist did not change in the end.
And at the expense of changing the path in nest-cli.json - it didnβt work, the server folder is also generated, itβs not clear how it gets there at all, I tried to immediately change the path in tsconfig.json but also to no avail
edit Can you screen what you got in dist when reproduced repository, please?
rm -rf dist && npm run build
dist/
βββ app.controller.d.ts
βββ app.controller.js
βββ app.controller.js.map
βββ app.module.d.ts
βββ app.module.js
βββ app.module.js.map
βββ auth
βΒ Β βββ auth.controller.d.ts
βΒ Β βββ auth.controller.js
βΒ Β βββ auth.controller.js.map
βΒ Β βββ auth.module.d.ts
βΒ Β βββ auth.module.js
βΒ Β βββ auth.module.js.map
βΒ Β βββ auth.service.d.ts
βΒ Β βββ auth.service.js
βΒ Β βββ auth.service.js.map
βΒ Β βββ dto
βΒ Β βββ create-user.dto.d.ts
βΒ Β βββ create-user.dto.js
βΒ Β βββ create-user.dto.js.map
βββ main.d.ts
βββ main.js
βββ main.js.map
βββ schemas
βΒ Β βββ user.schema.d.ts
βΒ Β βββ user.schema.js
βΒ Β βββ user.schema.js.map
βββ tsconfig.build.tsbuildinfo
3 directories, 25 files
rm -rf dist && npm run build
dist/
βββ app.controller.d.ts
βββ app.controller.js
βββ app.controller.js.map
βββ app.module.d.ts
βββ app.module.js
βββ app.module.js.map
βββ auth
β βββ auth.controller.d.ts
β βββ auth.controller.js
β βββ auth.controller.js.map
β βββ auth.module.d.ts
β βββ auth.module.js
β βββ auth.module.js.map
β βββ auth.service.d.ts
β βββ auth.service.js
β βββ auth.service.js.map
β βββ dto
β βββ create-user.dto.d.ts
β βββ create-user.dto.js
β βββ create-user.dto.js.map
βββ main.d.ts
βββ main.js
βββ main.js.map
βββ schemas
β βββ user.schema.d.ts
β βββ user.schema.js
β βββ user.schema.js.map
βββ tsconfig.build.tsbuildinfo
3 directories, 25 files
can you show your tsconfig.json
? Could be hard to tell what's going on without a reproduction
can you show your
tsconfig.json
? Could be hard to tell what's going on without a reproduction
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src", <-
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
}
nest-cli.json:
{
"collection": "@nestjs/schematics",
"sourceRoot": "./src" <-
}
Most likely this isn't nest's doing, but how Typescript's compiler works. It will try to keep your original directory structure in the dist of it's not a single directory (i.e. there's a directory with Typescript, that is not ignored, outside of the top level directory [usually src]). Best is just calling the Typescript compiler and trying to call dist/main
. If that's failing, you've probably got a file outside of src that is being compiled.
@lohevol read this: https://www.typescriptlang.org/tsconfig/rootDir.html and this: https://www.typescriptlang.org/tsconfig#baseUrl
Most likely this isn't nest's doing, but how Typescript's compiler works. It will try to keep your original directory structure in the dist of it's not a single directory (i.e. there's a directory with Typescript, that is not ignored, outside of the top level directory [usually src]). Best is just calling the Typescript compiler and trying to call
dist/main
. If that's failing, you've probably got a file outside of src that is being compiled.
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
Is there an existing issue for this?
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:
when I run
npm run start
ornpm run start:dev
I get an error: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 errorMinimum reproduction code
https://github.com/lohevol/nestjs-issue/
Steps to reproduce
npm run start:dev
npm run start:dev
npm run build
(i thought it can help to update)npm run start:dev
Expected behavior
what nest compile files without server folder, just dist/main, dist/app.module, etc.
Package
Other package
no
NestJS version
8.0.0
Packages versions
Node.js version
16.13.2
In which operating systems have you tested?
Other
No response