fix(rspack): preload @rspack/core before loading rspack config files - #36687
Open
federicobartoli wants to merge 1 commit into
Open
fix(rspack): preload @rspack/core before loading rspack config files#36687federicobartoli wants to merge 1 commit into
federicobartoli wants to merge 1 commit into
Conversation
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
On Node 22.18+/24 with native TypeScript stripping, `@nx/rspack/plugin` loads `rspack.config.ts` files via `require()`, which Node treats as ESM. When that ESM link fails (e.g. an extensionless `.ts` sibling import such as `./module-federation.config`), Node drops the failing config from its loader cache but leaves already-linked dependencies like `@rspack/core` cached in the un-instantiated state. The loader then falls back to swc/ts-node, and the re-required `@rspack/core` fails with ERR_INTERNAL_ASSERTION: Unexpected module status 0. Cannot require() ES Module .../@rspack/core/dist/index.js because it is not yet fully loaded. taking down project graph creation for every command. Load `@rspack/core` before any user rspack config is loaded, in `resolveUserDefinedRspackConfig` (used by both the inference plugin and the executor). Once it is fully evaluated, a failed config link can no longer leave it half-loaded. Same approach as the `vitest/node` preload in nrwl#34261. Fixes nrwl#36685
federicobartoli
force-pushed
the
fix/rspack-plugin-preload-rspack-core
branch
from
August 17, 2026 09:55
049dccc to
781d3d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
On Node 22.18+/24 with native TypeScript stripping (the default
NX_PREFER_NODE_STRIP_TYPESpath), the@nx/rspack/plugininference plugin can take down project graph creation for every command (nx show projects,nx serve,nx report, ...):Root cause (deterministic, not actually a
Promise.allrace):loadTsFilerequire()srspack.config.ts, which Node treats as ESM. When that ESM link fails — e.g. an extensionless.tssibling import likeimport config from './module-federation.config', which the legacy MF generators emit — Node removes the failing config from its ESM loader cache but leaves already-linked dependencies such as@rspack/core(pure ESM in v2) cached in the un-instantiated state (ModuleJobSynccleanup only deletes the module itself). Nx then falls back to swc/ts-node, the swc-compiled config (orloadRspackCore()inapplyBaseConfig) doesrequire('@rspack/core'), and Node'simportSyncForRequirehits the cached job with status 0 →ERR_INTERNAL_ASSERTION.Minimal standalone repro (Node 24.15,
@rspack/core@2.0.8):Expected Behavior
Graph creation succeeds.
@rspack/coreis loaded (viaimport()) before any userrspack.configfile is loaded, inresolveUserDefinedRspackConfig— the single place both the inference plugin and the executor go through. Once@rspack/coreis fully evaluated, a failed config link can no longer leave it half-loaded, and every laterrequire('@rspack/core')(from the fallback-compiled config or fromloadRspackCore) resolves from cache. This is the same approach as thevitest/nodepreload in #34261.The preload is lazy (only when a config actually needs to be loaded), so cached graphs pay nothing.
Verified locally on Node 24.15 with a 6-app workspace whose
rspack.config.tsfiles import@rspack/coreand an extensionless.tssibling: fails deterministically at iteration 1 afternx resetwithout the change; passes (targets inferred,devServer.portread from the config) with it. Added an e2e test ine2e/rspackcovering that shape.Related Issue(s)
Fixes #36685