nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.6k stars 2.36k forks source link

Referenced project ... must have setting "composite": true #27292

Open chriscurnow opened 3 months ago

chriscurnow commented 3 months ago

Current Behavior

My tsconfig files report an error:
Referenced project ... must have setting "composite": true.

Expected Behavior

Automatically generated tsconfig files should be error free.

GitHub Repo

No response

Steps to Reproduce

  1. create a new workspace
  2. create some projects
  3. Everything seems ok at first
  4. At some point I will be working on a project and suddenly this error will come up in the tsconfig file. I won't be working in the tsfonfig file. The error just appears.

Nx Report

nx (global)        : 19.4.3
nx                 : 19.5.3
@nx/js             : 19.5.3
@nx/jest           : 19.5.3
@nx/linter         : 19.5.3
@nx/eslint         : 19.5.3
@nx/workspace      : 19.5.3
@nx/angular        : 19.5.3
@nx/devkit         : 19.4.4
@nx/eslint-plugin  : 19.5.3
@nx/playwright     : 19.4.4
@nrwl/tao          : 19.5.3
@nx/web            : 19.5.3
@nx/webpack        : 19.5.3
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/playwright/plugin
@nx/eslint/plugin
---------------------------------------
Community plugins:
@ngrx/component-store : 18.0.2
@ngrx/effects         : 18.0.2
@ngrx/entity          : 18.0.2
@ngrx/operators       : 18.0.2
@ngrx/router-store    : 18.0.2
@ngrx/schematics      : 18.0.2
@ngrx/signals         : 18.0.2
@ngrx/store           : 18.0.2
---------------------------------------
The following packages should match the installed version of nx
  - @nx/devkit@19.4.4
  - @nrwl/devkit@19.4.4
  - @nx/playwright@19.4.4

To fix this, run `nx migrate nx@19.5.3`

Failure Logs

No response

Package Manager Version

No response

Operating System

Additional Information

I realise this report is essentially the same as #20957 but I don't believe it should have been closed. The error persists in automatically generated tsconfig files. This is a bug. The comment referenced a link which no longer exists: https://github.com/nrwl/nx/issues/20957#issuecomment-1873769215. @jaysoo commented here https://github.com/nrwl/nx/issues/20957#issuecomment-1883587356, that we were free to add composite:true, but

  1. We shouldn't have to
  2. This produces errors in many other places. This should be handled by the generators.
arndwestermann commented 3 months ago

I have the same error, this only popped up recently like a month or two ago or so. You can do a Restart Extension Host in VSCode, but if I make any changes to a lib or app, for example add a new file, this error comes back again. I hadn't any trouble with that a while ago, but right now this is really annoying.

chriscurnow commented 3 months ago

@arndwestermann, this has to do with the introduction of 'composite' in Typescript. It's not something I tend to spend a lot of time thinking about. I just want it to work.

I can't find where I found this but this arrangement seems to work.

In tsconfig.base.json, include

"compilerOptions:{ "declaration": true, "composite": true, "emitDeclarationOnly": true, }

And then in tsconfig.app.json or tsconfig.lib.json include

` "compilerOptions": {

"emitDecoratorMetadata": true,
"composite": true,
"declaration": true,
"declarationMap": true,

}, }`

The problem I have is I think the Nx generators should do this for us.

arndwestermann commented 3 months ago

@chriscurnow I think it is just sufficient enough to add this

"compilerOptions": {
    "declaration": true,
    "composite": true,
    "emitDeclarationOnly": true,
    ...
},

to the tsconfig.base.json, since any tsconfig.app.json/tsconfig.lib.json extend the local tsconfig.json which extends the tsconfig.base.json, at least this got already rid of the errors. Thanks for that. I agree, this IMOH should be done by the nx generator or by a migration.

EDIT:

@chriscurnow hm your solution unfortunately doesn't seem to work as I initially thought, even with putting also these flags into the app/lib configs, I'm getting a ton of these errors when I try to prod build the libs/apps

libs/shared/src/lib/util/index.ts:14:15 - error TS6307: File '[REDACTED]/libs/shared/src/lib/util/rxjs.util.ts' is not listed within the file list of project '[REDACTED]/libs/shared/tsconfig.lib.prod.json'. Projects must list all files or use an 'include' pattern.

export * from './rxjs.util';

If I understand it correctly It wants me to use the include: [] property to specify the files. but since tsconfig.lib.prod.json extends tsconfig.lib.json which has this "include": ["src/**/*.ts"] it should work or am I missing something?

cmrabet commented 3 months ago

I also have this problem and is very annoying. All libs are red flagged.

juanchavezlive commented 3 months ago

Same error here since several weeks

HenrikTusz commented 2 months ago

Same here

Banegasn commented 2 months ago

same problem here any news?

rs-r2d2 commented 2 months ago

+1

dgoerdes commented 2 months ago

I think not using the composite: true option is intended by NX. As setting it to true will make tsc to compile all of the referenced packages at once and depends on their code. However in a monorepo setup, as it goes for NX, we want to be able to compile packages individually and not treat everything as one connected thing.

It is annoying the IDE complains about it but it does not affect or causes any other issues than just the IDE complaining.

Please add information or correct me if this is wrong.

I would also love if someone has a solution to keep VSCode silent on this.

grigor-minasyan commented 2 months ago

what helped in my case was downgrading typescript to 5.5.3, the issue only appeared in my case with 5.5.4

alo commented 1 month ago

maybe @juristr can clarify this... 🤷

Thanks in advance

Khanon commented 1 month ago

More than two months of this issue and no solution?

TarikKalyoncu commented 2 weeks ago

helpp

demirtasdurmus commented 2 weeks ago

Any progress or ideas on this one?

Image

Image

pwglownia commented 1 week ago

I think not using the composite: true option is intended by NX. As setting it to true will make tsc to compile all of the referenced packages at once and depends on their code. However in a monorepo setup, as it goes for NX, we want to be able to compile packages individually and not treat everything as one connected thing.

It is annoying the IDE complains about it but it does not affect or causes any other issues than just the IDE complaining.

Please add information or correct me if this is wrong.

I would also love if someone has a solution to keep VSCode silent on this.

I would simply ts-ignore it, until we find the better solution :)

  "references": [
    // @ts-ignore -> https://github.com/nrwl/nx/issues/27292
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
  ],
KentoMoriwaki commented 1 week ago

I was also troubled by the same error, but it seems to have stopped occurring after I disabled the VSCode Plugin NX Console. This plugin might be the cause of the issue.

twestendorff commented 3 days ago

We have the same problem. The problem is no longer shown in VSCode when the NX Console version v18.24.1 is used.

Downgrading may be a workaround, but I agree with the issue creator, the problem shouldn't be there. In the IDE, especially for new project participants, it looks like they did something wrong/something is not working.

semanticist21 commented 3 days ago

My version is v20.0.5 but the error still occurs.

salez commented 2 days ago

this error keeps occuring from time to time, editing the file and saving it again makes the error goes away, but it's pretty annoying