镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(commonjs): handle node: builtins with strictRequires: auto - #1930

Merged
shellscape merged 1 commit into
rollup:masterfrom
danielroe:fix/commonjs-strict-requires
Oct 24, 2025
Merged

shellscape merged 1 commit into
rollup:masterfrom
danielroe:fix/commonjs-strict-requires

Conversation

@danielroe

Copy link
Copy Markdown
Contributor

Rollup Plugin Name: @rollup/plugin-commonjs

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

resolves #1929

Description

this fixes an issue introduced in #1909, which added special handling for node: builtins to avoid eager loading in wrapped modules...

@danielroe
danielroe requested a review from shellscape as a code owner October 24, 2025 02:59
@shellscape

Copy link
Copy Markdown
Collaborator

Thanks for the PR. Please take some time to describe what your changes do differently.

We're also discussing this in #1924

@danielroe

Copy link
Copy Markdown
Contributor Author

my apologies!

charlie's summary in the linked issue and the code comment in this PR cover what i was intending, but i'll write in more detail when i'm back at my computer

isExternalWrapped
) {
let resolvedDependencyId = dependencyId;
if (parentMeta.isCommonJS === IS_WRAPPED_COMMONJS && !allowProxy && isExternalWrapped) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. Previously, we checked parentMeta.initialCommonJSType === IS_WRAPPED_COMMONJS instead of parentMeta.isCommonJS === IS_WRAPPED_COMMONJS. With strictRequires: 'auto', I believe the initial type (before cycle detection) can differ from the final type.

Comment on lines +206 to +213
} else if (isExternalWrapped && !allowProxy) {
// If the parent is not wrapped but the dependency is a node: builtin external,
// unwrap the EXTERNAL_SUFFIX so it's treated as a normal external.
// This avoids trying to load the lazy __require proxy for non-wrapped contexts.
const actualExternalId = unwrapId(dependencyId, EXTERNAL_SUFFIX);
if (actualExternalId.startsWith('node:')) {
resolvedDependencyId = actualExternalId;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. node: builtins with the EXTERNAL_SUFFIX were always loaded with getExternalBuiltinRequireProxy() which only exports __require(). However, when the parent module is not wrapped (no cycles detected with strictRequires: 'auto'), the generated code tried to import a default export that didn't exist.

(so in this case we can remove the suffix)

@shellscape
shellscape requested review from CharlieHelps and removed request for CharlieHelps and shellscape October 24, 2025 13:24
@shellscape

Copy link
Copy Markdown
Collaborator

thanks!

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.

[commonjs] "default" is not exported by some node core modules with strictRequires: 'auto'

2 participants