-
-
Notifications
You must be signed in to change notification settings - Fork 611
fix(commonjs): handle node: builtins with strictRequires: auto
#1930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(commonjs): handle node: builtins with strictRequires: auto
#1930
Conversation
|
Thanks for the PR. Please take some time to describe what your changes do differently. We're also discussing this in #1924 |
|
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Previously, we checked
parentMeta.initialCommonJSType === IS_WRAPPED_COMMONJSinstead ofparentMeta.isCommonJS === IS_WRAPPED_COMMONJS. With strictRequires: 'auto', I believe the initial type (before cycle detection) can differ from the final type.
| } 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node:builtins with the EXTERNAL_SUFFIX were always loaded withgetExternalBuiltinRequireProxy()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)

Rollup Plugin Name:
@rollup/plugin-commonjsThis PR contains:
Are tests included?
Breaking Changes?
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...