nrwl / nx

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

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

Open chriscurnow opened 1 month ago

chriscurnow commented 1 month 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 1 month 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 1 month 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 1 month 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 1 month ago

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

juanchavezlive commented 1 month ago

Same error here since several weeks

HenrikTusz commented 2 weeks ago

Same here

Banegasn commented 2 weeks ago

same problem here any news?

rs-r2d2 commented 1 week ago

+1

dgoerdes 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.

grigor-minasyan commented 6 days ago

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