Skip to content

feat: add node compatibility guard and lazy command loading for rspack#1397

Open
dannyhw wants to merge 2 commits into
feat/rspack-2-foundationsfrom
feat/rspack-2-node-guard
Open

feat: add node compatibility guard and lazy command loading for rspack#1397
dannyhw wants to merge 2 commits into
feat/rspack-2-foundationsfrom
feat/rspack-2-node-guard

Conversation

@dannyhw

@dannyhw dannyhw commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part of the Rspack 2 support effort — PR 2b of the stack, stacked on #1394 (feat/rspack-2-foundations), so the diff against its base shows only this PR's changes.

Rspack 2 is published as a pure ESM package with engines.node: "^20.19.0 || >=22.12.0" — the Node versions where loading ESM through require() is supported. On older Node versions, touching @rspack/core v2 crashes with an obscure ERR_REQUIRE_ESM.

This PR makes that failure mode actionable:

  • ensureNodeCompat.ts (new): raises a clear CLIError ("Rspack X requires Node.js ^20.19.0 || >=22.12.0 — found Y. Upgrade Node.js or use @rspack/core@1 instead.") when the installed Rspack major is ≥ 2 and the current Node version is unsupported. Uses the version-detection helpers from feat: add rspack version detection helpers #1394, which resolve @rspack/core/package.json without importing the package — safe on any Node version.
  • commands/rspack/index.ts: the start/bundle command modules are now imported lazily inside the command funcs. The guard runs before @rspack/core is touched, and loading react-native.config.js no longer imports the bundler at all.
  • profile/index.ts: refactored onto the shared version helper (getRspackVersion) instead of importing rspackVersion from @rspack/core — no behavior change; the version-routing logic is identical.

start.ts and bundle.ts are untouched.

The only user-visible change (the friendlier Node-version error) is covered by a patch changeset.

References

Validation

All run at the repo root on this branch (workspace catalog is still Rspack 1.x, as expected at this point in the stack):

  • pnpm install — clean
  • pnpm turbo run typecheck test --force — 17/17 tasks successful (packages/repack unit suite: 29 suites, 280 tests, 22 snapshots — all passing)
  • pnpm lint:ci — clean (460 files, no fixes)

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
repack-website Ready Ready Preview, Comment Jul 6, 2026 7:27pm

Request Review

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 609ce32

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@callstack/repack Patch
@callstack/repack-plugin-expo-modules Patch
@callstack/repack-plugin-nativewind Patch
@callstack/repack-plugin-reanimated Patch
@callstack/repack-dev-server Patch
@callstack/repack-init Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/repack/src/commands/rspack/ensureNodeCompat.ts
- unit-test ensureNodeSupportsRspack against mocked rspack/node versions,
  including the ^20.19.0 || >=22.12.0 range boundaries
- assert the rspack commands module registers without loading @rspack/core
  (a throwing @rspack/core mock fails the suite on any eager load)
- assert lazy bundle/start run the guard before importing the command
  modules and skip them entirely when the guard throws
- lower dynamic import() to require() in the jest babel env only;
  published output keeps import() as-is
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.

1 participant