Skip to content

fix: remove default javascript/auto type for JavaScript modules#5955

Closed
chenjiahan wants to merge 1 commit intomainfrom
js_module_type_0827
Closed

fix: remove default javascript/auto type for JavaScript modules#5955
chenjiahan wants to merge 1 commit intomainfrom
js_module_type_0827

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

This PR removes the type: 'javascript/auto' from the rule for JavaScript modules.

When Rspack encounters modules with type: "module" in package.json or modules with .mjs and .mts extensions, Rspack will configure these modules with javascript/esm by default.

If Rsbuild sets javascript/auto for ES modules, this change will break the ESM/CJS interop. For example, when a user writes an .mjs file and imports a CJS module, interop runtime should be added. However, with javascript/auto, the interop won't be added.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings August 27, 2025 08:33
@netlify
Copy link
Copy Markdown

netlify bot commented Aug 27, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 50bf076
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68aec2da6844040008d89b31
😎 Deploy Preview https://deploy-preview-5955--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 49 (🔴 down 26 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the explicit type: 'javascript/auto' configuration from JavaScript module rules to fix ESM/CJS interoperability issues. When Rspack encounters ES modules (.mjs, .mts files or modules with type: "module" in package.json), it automatically sets javascript/esm by default, but the explicit javascript/auto override was breaking the necessary interop runtime for importing CJS modules from ESM contexts.

  • Removes the type: 'javascript/auto' line from the SWC loader rule configuration
  • Updates all test snapshots to reflect the removal of this configuration
  • Allows Rspack to handle JavaScript module type detection automatically

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

File Description
packages/core/src/plugins/swc.ts Removes the explicit type: 'javascript/auto' from the JavaScript module rule
packages/core/tests/snapshots/*.snap Updates test snapshots to reflect the removed type configuration
packages/plugin-/tests/snapshots/.snap Updates plugin test snapshots for consistency
packages/compat/webpack/tests/snapshots/*.snap Updates webpack compatibility test snapshots

@chenjiahan
Copy link
Copy Markdown
Member Author

chenjiahan commented Aug 27, 2025

Closed as it is a potential breaking change (javascript/esm and javascript/auto behave differently).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants