-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Current Behavior
When using Nx React Module Federation with Rspack, running nx run-many -t e2e before nx run-many -t typecheck causes TypeScript declaration generation to fail.
The e2e tasks start nx preview for the remotes, which uses Rspack and the ts-checker-rspack-plugin.
This plugin generates .tsbuildinfo files in the workspace but does not emit .d.ts files in dist/.
Afterwards, when the typecheck task runs with --emitDeclarationOnly, TypeScript fails because it expects corresponding .d.ts outputs for the existing .tsbuildinfo.
Expected Behavior
nx run-many -t typecheck should succeed regardless of whether Rspack (via nx preview ) was executed before it.
Running tasks like e2e should not leave partially built .tsbuildinfo caches that cause subsequent tsc --emitDeclarationOnly runs to fail.
GitHub Repo
No response
Steps to Reproduce
Setup project:
pnpx create-nx-workspace@latest mf-test(choose Playwright for e2e tests)nx add @nx/reactnx g @nx/react:host apps/react/with-remotes/shell --remotes=remote1,remote2
Run e2e and typecheck (in this order):
nx run-many -t e2enx run-many -t typecheck
To reproduce again (clean state), run this first:
find . -type d \( -name 'out-tsc' -o -name 'dist' \) -not -path '*/node_modules/*' -exec rm -rf {} + && nx reset
Nx Report
Node : 22.17.1
OS : linux-x64
Native Target : x86_64-linux
pnpm : 10.20.0
nx (global) : 22.0.3
nx : 22.0.3
@nx/js : 22.0.3
@nx/jest : 22.0.3
@nx/eslint : 22.0.3
@nx/devkit : 22.0.3
@nx/eslint-plugin : 22.0.3
@nx/module-federation : 22.0.3
@nx/playwright : 22.0.3
@nx/react : 22.0.3
@nx/rspack : 22.0.3
@nx/web : 22.0.3
typescript : 5.9.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/rspack/plugin
@nx/eslint/plugin
@nx/playwright/plugin
@nx/jest/plugin
---------------------------------------
Cache Usage: 1.48 MB / 100.69 GBFailure Logs
> nx run remote2:typecheck
> tsc --build --emitDeclarationOnly
src/app/app.spec.tsx:3:17 - error TS6305: Output file '<...>/apps/react/with-remotes/remote2/dist/app/app.d.ts' has not been built from source file '<...>/apps/react/with-remotes/remote2/src/app/app.tsx'.
3 import App from './app';
~~~~~~~
Found 1 error.
> nx run remote1:typecheck
> tsc --build --emitDeclarationOnly
src/app/app.spec.tsx:3:17 - error TS6305: Output file '<...>/apps/react/with-remotes/remote1/dist/app/app.d.ts' has not been built from source file '<...>/apps/react/with-remotes/remote1/src/app/app.tsx'.
3 import App from './app';
~~~~~~~
Found 1 error.
✖ nx run remote2:typecheck
✖ nx run remote1:typecheck
————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Ran target typecheck for 6 projects (1s)
✖ 2/2 targets failed, including the following:
- nx run remote2:typecheck
- nx run remote1:typecheck
… 4/6 targets had not started.Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
This appears to be caused by the ts-checker-rspack-plugin being invoked in write mode when used by Nx’s preview/serve commands.
When rspack runs, it writes .tsbuildinfo files but not .d.ts files, confusing subsequent TypeScript builds.
Proposed Fix:
In packages/rspack/src/plugins/utils/apply-base-config.ts - when configuring ts-checker-rspack-plugin options - set:
pluginConfig.typescript.mode = "readonly";
This prevents Rspack from modifying .tsbuildinfo and avoids polluting the cache for later tsc --emitDeclarationOnly runs.
Another fix/workaround can be to change the preset so that the preview target depends on the typecheck target for shell and remotes (like the serve target). This way typecheck always runs first.
Some aspects of this bug were already addressed by:
#32340 and #31929
but did not solve this specific issues.