Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sync] typescript-sync generator adds project references for implicit dependencies #28997

Open
1 of 4 tasks
cogwirrel opened this issue Nov 19, 2024 · 0 comments · May be fixed by #28998
Open
1 of 4 tasks

[sync] typescript-sync generator adds project references for implicit dependencies #28997

cogwirrel opened this issue Nov 19, 2024 · 0 comments · May be fixed by #28998

Comments

@cogwirrel
Copy link
Contributor

Current Behavior

The typescript sync generator adds references for all projects in the dependency graph if they have a tsconfig (with composite: true).

This currently includes implicit dependencies, which are not explicitly referenced in code and therefore don't require project references.

See #28839 - where batch builds also skip implicit dependencies.

For a tangible example, if I have a monorepo with some infrastructure project (eg CDK), and a website project (eg a React app) - I might have my infrastructure project deploy my website but not directly reference any of its code, and so use an implicit dependency to ensure build order. The sync generator will still add a reference as both of these are TypeScript projects, but I can get an error such as this when moduleResolution is is different for the two projects:

      ../website/tsconfig.app.json:3:3 - error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
      
      3   "compilerOptions": {
          ~~~~~~~~~~~~~~~~~
      
      ../website/tsconfig.app.json:3:3 - error TS5109: Option 'moduleResolution' must be set to 'NodeNext' (or left unspecified) when option 'module' is set to 'NodeNext'.
      
      3   "compilerOptions": {
          ~~~~~~~~~~~~~~~~~

Expected Behavior

Implicit dependency tsconfigs should not be referenced by the projects which depend on them. Only explicit dependencies should be referenced in project tsconfigs.

GitHub Repo

https://github.com/cogwirrel/nx-sync-generator-implicit-deps-example

Steps to Reproduce

  1. Clone the example repo
  2. pnpm i
  3. pnpm nx run-many --target build --all and observe error

If you then delete the references to the website in packages/infra/tsconfig.json and packages/infra/tsconfig.lib.json and rebuild, Nx prompts to run the sync generator. If we skip running the sync generator, the build succeeds, otherwise if we run the sync generator the build fails.

Nx Report

NX   Report complete - copy this into the issue template

Node           : 20.18.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 9.13.0

nx             : 20.1.2
@nx/js         : 20.1.2
@nx/eslint     : 20.1.1
@nx/workspace  : 20.1.2
@nx/devkit     : 20.1.2
@nx/react      : 20.1.1
@nx/vite       : 20.1.2
@nx/web        : 20.1.1
typescript     : 5.5.4
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/vite/plugin
---------------------------------------
The following packages should match the installed version of nx
  - @nx/[email protected]
  - @nx/[email protected]
  - @nx/[email protected]

To fix this, run `nx migrate [email protected]`

Failure Logs

Failure logs will vary depending on the use case, but in the example code they are as follows:


      ../website/tsconfig.app.json:3:3 - error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
      
      3   "compilerOptions": {
          ~~~~~~~~~~~~~~~~~
      
      ../website/tsconfig.app.json:3:3 - error TS5109: Option 'moduleResolution' must be set to 'NodeNext' (or left unspecified) when option 'module' is set to 'NodeNext'.
      
      3   "compilerOptions": {
          ~~~~~~~~~~~~~~~~~

Package Manager Version

pnpm 9.13.0

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

cogwirrel added a commit to cogwirrel/nx that referenced this issue Nov 19, 2024
…cies in sync generator

This change omits references to implicit dependency tsconfigs for typescript projects in the sync
generator, since given that they are not referenced directly in code there is no need for project
references.

Fixes nrwl#28997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant