Skip to content

Conversation

@Timeless0911
Copy link
Contributor

@Timeless0911 Timeless0911 commented Jan 6, 2026

Summary

This PR updates requireShim to use the default import from node:module instead of a named import.

In the previous PR (#1431), we switched to import { createRequire } from "node:module". However, if the user's code also defines a variable named createRequire, this shim injection could cause a naming conflict.

see https://github.com/rstackjs/rstack-ecosystem-ci/actions/runs/20743602225/job/59555591523

This PR resolves the issue by using a namespaced default import:

// Before (potential conflict)
import { createRequire } from "node:module";
const require = /*#__PURE__*/ createRequire(import.meta.url);

// After (safe)
import __rslib_shim_module__ from "node:module";
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(import.meta.url);

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings January 6, 2026 09:54
@netlify
Copy link

netlify bot commented Jan 6, 2026

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit e3369c2
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/695cdbc7fa3f710008725148
😎 Deploy Preview https://deploy-preview-1433--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@Timeless0911 Timeless0911 force-pushed the fix/require-shim-conflict branch from e3369c2 to ff006d0 Compare January 6, 2026 09:56
Copy link
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 fixes a potential naming conflict issue by switching from a named import to a default import when injecting the require shim in ESM outputs. The change prevents collisions when user code defines a variable named createRequire.

Key changes:

  • Updated the require shim to use import __rslib_shim_module__ from 'node:module' instead of import { createRequire } from "node:module"
  • Updated test snapshots to reflect the new shim format
  • Updated both English and Chinese documentation with the new code examples

Reviewed changes

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

File Description
packages/core/src/plugins/shims.ts Changed the require shim from named import to default import with namespaced identifier
tests/integration/shims/index.test.ts Updated test snapshot to match new shim format
website/docs/en/config/lib/shims.mdx Updated English documentation with new code example
website/docs/zh/config/lib/shims.mdx Updated Chinese documentation with new code example

After thoroughly reviewing all changes, I found no issues with this PR. The implementation is correct, all tests have been properly updated, and the documentation accurately reflects the changes. The solution effectively addresses the naming conflict issue while maintaining compatibility and following established conventions in the codebase.


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

@Timeless0911 Timeless0911 merged commit 3ef4ab2 into main Jan 6, 2026
17 checks passed
@Timeless0911 Timeless0911 deleted the fix/require-shim-conflict branch January 6, 2026 11:10
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