[Nest] Possible Bug in autogenerated TSConfig
See original GitHub issue- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed
- I’m reporting the issue to the correct repository (not related to Angular, AngularCLI or any dependency)
Expected Behavior
In my API, I have a circular dependency between Account
and Profile
(one Account
has one Profile
assigned; one Profile
belongs to one Account
). This is realized with the TypeORM @OneToOne(...)
relationship.
This api should properly build and run.
Current Behavior
The ng serve PROJECT
command throws circular dependency
warnings (see #1649 , #1661) and “refuses” to properly boot. In this context, i noticed the following error on the terminal:
ReferenceError: Cannot access 'Account' before initialization
at Module.Account (...\dist\apps\api\main.js:544:99)
...
If i trace down the stacktrace, i end up in the circular dependency between Account
and Profile
(as described above).
Solution
I manage to solve this issue by adding the following lines to the apps\api\tsconfig.app.json
file:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs", // <-- here
"target": "es2017", // <-- here
"types": ["node"]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"]
}
The “autogenerated” tsconfig.app.json
file when running
ng g @nrwl/nest:app api
omits those lines. In the sample project from nestjs
( https://github.com/nestjs/nest/blob/master/sample/01-cats-app/tsconfig.json ) these lines are required.
I think, we should add those lines by default - this can be done in the nest schematics
right? Shall i add a PR for this @FrozenPandaz ?
When running ng serve api
it still throws a lot of circular dependency
warnings, however, the application successfully “compiles” and can be executed. The issue with the circular dependency
was introduced somewhere between 8.2 and 8.4, i guess…
All the best
Issue Analytics
- State:
- Created 4 years ago
- Reactions:14
- Comments:16 (7 by maintainers)
@fstn I can run jest test without any problem. Here are my tsconfigs for reference:
apps/api/tsconfig.spec.json
apps/api/tsconfig.json
apps/api/tsconfig.app.json
The problem must be on your side.
@bcabanes and @vsavkin : I would advise to re-open this issue because the problem is actually not solved!