Skip to content

TypeScript Project Linking enablement is unnecessarily fragile #35846

@johncrim

Description

@johncrim

Current Behavior

I wanted to neaten things up a bit in our repo by moving some files and deduplicating tsconfig logic. Unfortunately doing this breaks the TypeScript Project Linking detection. The real problem is that the project linking features don't work unless a number of arbitrary and otherwise unnecessary conditions are met. When these conditions are not met, there is no warning or observable notice (that I have seen, I'm relatively new to nx) other than the fact that the project linking features stop working.

For example, I moved ~/tsconfig.base.json to ~/eng/ts/tsconfig.base.json, which breaks project linking features, even though there's no reason it should break.

The code causing this fragility is in isWorkspaceSetupWithTsSolution(), which is duplicated in 2 different packages in nx:
workspace/utilities/typescript/ts-solution-setup.ts
js/utils/typescript/ts-solution-setup.ts

Any of these changes break project linking without warning:

  1. Moving the location of the ~/tsconfig.base.json file (there's no other reason it has to be in the repo root)
  2. Using a different name than ~/tsconfig.base.json
  3. Omitting empty files: [] or include: [] arrays from ~/tsconfig.json (this is required even though the empty array could be specified in the base file)
  4. composite: true must be specified in ~/tsconfig.base.json - this one is functionally required, which makes sense, but it should work if provided in a different file

Expected Behavior

Project linking should work as documented long as the functional requirements are in place, eg:

  1. composite: true is set in the ~/tsconfig.json file, after it is combined with any tsconfig files that it extends
  2. Package manager workspaces is enabled
  3. Are there any other requirements that are strictly needed to enable it?

Or, if there's a strong backward compatibility concern to preserve unlinked behavior, then add a property to nx.json to enable/disable project linking.

GitHub Repo

https://github.com/johncrim/nx-test-project-linking

Steps to Reproduce

  1. git clone git@github.com:johncrim/nx-test-project-linking.git
  2. nx sync => shows no updates b/c tsconfig.base.json is in ~/eng dir
  3. Move ~/eng/tsconfig.base.json to ~/tsconfig.base.json and fix the reference in ~/tsconfig.json to point to the new location
  4. nx sync => updates ~/tsconfig.json and ~/lib2/tsconfig.lib.json b/c project linking is detected

Nx Report

Node           : 24.10.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 11.6.1
daemon         : Available

nx (global)        : 22.7.1
nx                 : 22.7.5
@nx/js             : 22.7.5
@nx/eslint         : 22.7.5
@nx/workspace      : 22.7.5
@nx/devkit         : 22.7.5
@nx/eslint-plugin  : 22.7.5
@nx/vitest         : 22.7.5
typescript         : 5.9.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/eslint/plugin
@nx/vitest
---------------------------------------
Cache Usage: 0.00 B / 95.10 GB

Failure Logs

Package Manager Version

No response

Operating System

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

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions