fix(rsbuild-plugin): replace direct JSON import with builder define to fix Node.js >= 22#4564
fix(rsbuild-plugin): replace direct JSON import with builder define to fix Node.js >= 22#4564
Conversation
…o fix Node.js >= 22
- Remove `import pkgJson from '../../package.json'` which throws on Node.js >= 22
without `assert { type: 'json' }` / `with { type: 'json' }`
- Inject package name via `source.define` in rslib.config.ts so the value is
inlined as a string literal at build time
- Add `src/env.d.ts` to declare the `__RSBUILD_PLUGIN_PACKAGE_NAME__` global
- Add `no-restricted-imports` ESLint rule in root config to ban `*.json` imports
inside `**/src/**` files going forward
- Fix `packages/runtime-tools/.eslintrc.json` ignorePatterns overriding root
`.eslintignore` causing `dist/` to be linted
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 1334efa The changes in this PR will be included in the next version bump. This PR includes changesets to release 45 packages
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83ea016794
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| process.env['IS_ESM_BUILD'] === 'true' | ||
| ? esmRelativePath | ||
| : cjsRelativePath, |
There was a problem hiding this comment.
Keep
IS_ESM_BUILD dot-access for define substitution
In resolvePackageFile(), switching to process.env['IS_ESM_BUILD'] breaks the build-time replacement configured in packages/modernjs/rslib.config.ts:30-31 and :44-45, which only defines the exact expression process.env.IS_ESM_BUILD. In the published ESM bundle this condition will stay runtime-dependent, and for normal consumers where that env var is unset it will always pick the CJS paths, so the ESM package can resolve dist/cjs/... plugins instead of the intended .mjs files.
Useful? React with 👍 / 👎.
| process.env['IS_ESM_BUILD'] === 'true' | ||
| ? esmRelativePath | ||
| : cjsRelativePath, |
There was a problem hiding this comment.
Preserve dot-access for
IS_ESM_BUILD in v3 build
This has the same regression as the non-v3 package: packages/modernjs-v3/rslib.config.ts:30-31 and :44-45 inject process.env.IS_ESM_BUILD, but the new bracket access is a different expression and will not be replaced at build time. As a result, the generated ESM artifact now depends on a runtime env var that consumers do not set, so resolvePackageFile() can incorrectly load the CJS runtime plugin paths.
Useful? React with 👍 / 👎.
…GE_NAME__ for consistency
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/data-prefetch
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
Bundle Size Report15 package(s) changed, 25 unchanged. Package dist + ESM entry
Bundle targets
Consumer scenarios
Total dist (raw): 6.31 MB (-404 B (-0.0%)) Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as |
Description
Summary
Importing JSON files directly (e.g. import pkg from '../../package.json') throws an error in Node.js >= 22 without an explicit with { type: 'json' }
assertion. This PR eliminates the import entirely by injecting the package name as a compile-time string literal via source.define in rslib.config.ts, so no
JSON import exists in the output at all.
Additionally, an ESLint rule is added to prevent the same issue from being reintroduced across any src/ file in the monorepo, and a pre-existing bug where
runtime-tools lint was scanning dist/ artifacts is also fixed.
Changes
RSBUILD_PLUGIN_PACKAGE_NAME
inlines it as a string literal at build time
Related Issue
Types of changes
Checklist