Skip to content

feat: Upgrade @rspack/core to v2 and fix breaking changes#419

Draft
yoannmoinet wants to merge 1 commit into
masterfrom
yoann/upgrade-rspack-to-v2-and-fix-breaking-ch-fe06544d
Draft

feat: Upgrade @rspack/core to v2 and fix breaking changes#419
yoannmoinet wants to merge 1 commit into
masterfrom
yoann/upgrade-rspack-to-v2-and-fix-breaking-ch-fe06544d

Conversation

@yoannmoinet

Copy link
Copy Markdown
Member

What and why?

Fixes #418.

  • Widens the @datadog/rspack-plugin peer dependency from "1.x" to "1.x || 2.x" so users on rspack v2 are no longer blocked.
  • Upgrades the internal @rspack/core dev/test dependency from 1.4.92.0.8.
  • Fixes the two rspack v2 breaking changes that affected this codebase.
  • Fixes a Jest ESM incompatibility introduced by rspack v2 being pure ESM.

How?

Rspack v2 breaking changes addressed:

  • experiments.css removed — rspack v2 dropped this option (CSS support is now always on). Removed it from configXpack() in packages/tools/src/bundlers.ts; leaving it in caused rspack to throw on unknown config.
  • Explicit CSS module rule required — rspack v2 requires { test: /\.css$/, type: 'css' } in module.rules for CSS imports to be processed. Added it alongside the existing ts-loader rule so the easy_project_with_css fixture tests continue to work.

Jest ESM compatibility:

@rspack/core v2 ships as a pure ESM package ("type": "module"). The test suite runs Jest with --experimental-vm-modules, which causes Jest's shouldLoadAsEsm() to return true for any package with "type": "module" — making require('@rspack/core') throw ERR_REQUIRE_ESM before the transformer ever runs.

Fix: added a custom Jest resolver (rspack-jest-resolver.cjs) that intercepts require('@rspack/core') and redirects it to a .cjs shim (rspack-cjs-shim.cjs). Two properties make this work:

  1. The .cjs extension causes shouldLoadAsEsm() to return false unconditionally, bypassing Jest's ESM guard.
  2. Inside the shim, createRequire() from node:module is used instead of the module's own require. createRequire() is not patched by Jest and uses Node's native loader, which supports require(esm) natively on Node ≥ 20.17.

No test logic was changed; all pre-existing failures (macOS fsmonitor--daemon.ipc socket-copy errors in git integration tests) are unrelated to this PR and reproduce identically with the webpack bundler.

Fixes #418 - widen rspack peer dependency to support v2.

Breaking changes addressed:
- Remove `experiments.css: true` from bundler config (removed in rspack v2;
  CSS processing is now always available)
- Add explicit CSS module rule `{ test: /\.css$/, type: 'css' }` required
  in rspack v2 for CSS imports to work

Jest ESM compatibility fix:
- @rspack/core v2 is pure ESM ("type": "module"), which causes Jest's CJS
  runtime to throw ERR_REQUIRE_ESM when --experimental-vm-modules is active
- Add a custom Jest resolver (rspack-jest-resolver.cjs) that maps
  @rspack/core to a .cjs shim file
- The .cjs shim uses createRequire() (Node's native, non-Jest-intercepted
  loader) to load the real rspack, bypassing Jest's module interception
  while preserving Node 20.17+'s require(esm) support

Changes:
- packages/tests/package.json: @rspack/core 1.4.9 -> 2.0.8
- packages/tools/package.json: @rspack/core 1.4.9 -> 2.0.8
- packages/tools/src/bundlers.ts: remove experiments.css, add CSS rule
- packages/published/rspack-plugin/package.json: peerDep 1.x -> 1.x || 2.x
- packages/tests/jest.config.ts: add custom resolver for @rspack/core
- packages/tests/src/_jest/rspack-jest-resolver.cjs: custom Jest resolver
- packages/tests/src/_jest/rspack-cjs-shim.cjs: CJS shim for rspack v2
@yoannmoinet yoannmoinet marked this pull request as ready for review June 16, 2026 15:22
@yoannmoinet yoannmoinet marked this pull request as draft June 16, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@datadog/rspack-plugin peer-pins @rspack/core "1.x" — verified working with Rspack 2, please widen the range

1 participant