Skip to content

fix: preserve filename and dirname for ESM bundles#6811

Merged
chenjiahan merged 1 commit intomainfrom
dirname_1220
Dec 20, 2025
Merged

fix: preserve filename and dirname for ESM bundles#6811
chenjiahan merged 1 commit intomainfrom
dirname_1220

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

@chenjiahan chenjiahan commented Dec 20, 2025

Summary

Disable automatic __dirname / __filename / import.meta.dirname / import.meta.filename polyfills when output.module is enabled so ESM bundles preserve native Node.js / browser behavior.

Related link

Checklist

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

Copilot AI review requested due to automatic review settings December 20, 2025 09:16
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 20, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 261ace0
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/69466978861aca0009900c67
😎 Deploy Preview https://deploy-preview-6811--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: 72 (🔴 down 11 from production)
Accessibility: 100 (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 disables automatic polyfills for __dirname, __filename, import.meta.dirname, and import.meta.filename in ESM bundles (when output.module is enabled) to preserve native Node.js and browser behavior.

Key Changes:

  • Added configuration to disable __dirname and __filename polyfills in the ESM plugin
  • Added comprehensive test coverage for both web and node targets to verify the behavior

Reviewed changes

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

Show a summary per file
File Description
packages/core/src/plugins/esm.ts Sets chain.node configuration to disable __dirname and __filename polyfills when ESM output is enabled
e2e/cases/polyfill/dirname-filename-web/src/index.js Test source file that checks the types of dirname/filename variables in browser context
e2e/cases/polyfill/dirname-filename-web/rsbuild.config.ts Configuration enabling ESM output for web target test
e2e/cases/polyfill/dirname-filename-web/index.test.ts Test verifying that dirname/filename are not polyfilled (remain undefined) in web target
e2e/cases/polyfill/dirname-filename-node/src/index.js Test source file that outputs dirname/filename values in Node.js context
e2e/cases/polyfill/dirname-filename-node/rsbuild.config.ts Configuration enabling ESM output for node target test
e2e/cases/polyfill/dirname-filename-node/index.test.ts Test verifying that dirname/filename are preserved as-is in the bundled output for node target

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chenjiahan chenjiahan merged commit 489b747 into main Dec 20, 2025
19 checks passed
@chenjiahan chenjiahan deleted the dirname_1220 branch December 20, 2025 09:36
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.

2 participants