question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
hakimiocommented, Aug 13, 2020

@fstn I can run jest test without any problem. Here are my tsconfigs for reference: apps/api/tsconfig.spec.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["jest", "node"]
  },
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}

apps/api/tsconfig.json

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "types": ["node", "jest"],
    "emitDecoratorMetadata": true,
    "target": "es2017",
    "module": "commonjs",
    "removeComments": true
  },
  "include": ["**/*.ts"]
}

apps/api/tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "types": ["node"]
  },
  "exclude": ["**/*.spec.ts"],
  "include": ["**/*.ts"]
}

The problem must be on your side.

5reactions
johannesschobelcommented, Sep 9, 2019

@bcabanes and @vsavkin : I would advise to re-open this issue because the problem is actually not solved!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript does not resolve modules through tsconfig. ...
Saying that this issue is not a bug but a configuration issue doesn't seem right to me. If I can compile my project...
Read more >
Understanding TypeScript's “Compilation Process” & the ...
When you run tsc command in a directory, TypeScript compiler looks for the tsconfig.json file in the current directory and if it doesn't...
Read more >
VS 15.6 ignores tsconfig.json and TypeScriptCompileBlocked
We have determined that this issue is not a bug. In Visual Studio 2017 version 15.5 and earlier, it was possible to have...
Read more >
Configuration Reference
A directory (relative to outputDir ) to nest generated static assets (js, css, img, fonts) under. TIP. assetsDir is ignored when overwriting the ......
Read more >
How to build a Serverless backend with TypeScript, Node. ...
The code will be released on an AWS Lambda function, whose invocation will only be possible through an API Gateway. Obviously, a Data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found