Skip to content
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

module: do not warn when accessing __esModule of unfinished exports #33048

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,13 +825,16 @@ function emitCircularRequireWarning(prop) {
// warns when non-existend properties are accessed.
const CircularRequirePrototypeWarningProxy = new Proxy({}, {
get(target, prop) {
if (prop in target) return target[prop];
// Allow __esModule access in any case because it is used in the output
// of transpiled code to determine whether something comes from an
// ES module, and is not used as a regular key of `module.exports`.
if (prop in target || prop === '__esModule') return target[prop];
emitCircularRequireWarning(prop);
return undefined;
},

getOwnPropertyDescriptor(target, prop) {
if (ObjectPrototypeHasOwnProperty(target, prop))
if (ObjectPrototypeHasOwnProperty(target, prop) || prop === '__esModule')
return ObjectGetOwnPropertyDescriptor(target, prop);
emitCircularRequireWarning(prop);
return undefined;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/cycles/warning-esm-half-transpiled-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./warning-esm-half-transpiled-b.js');
2 changes: 2 additions & 0 deletions test/fixtures/cycles/warning-esm-half-transpiled-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = require('./warning-esm-half-transpiled-a.js');
a.__esModule;
7 changes: 7 additions & 0 deletions test/parallel/test-module-circular-dependency-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ assert.strictEqual(Object.getPrototypeOf(classExport).name, 'Parent');
const esmTranspiledExport =
require(fixtures.path('cycles', 'warning-esm-transpiled-a.js'));
assert.strictEqual(esmTranspiledExport.__esModule, true);

// If module.exports.__esModule is being accessed but is not present, e.g.
// because only the one of the files is a transpiled ES module, no warning
// should be emitted.
const halfTranspiledExport =
require(fixtures.path('cycles', 'warning-esm-half-transpiled-a.js'));
assert.strictEqual(halfTranspiledExport.__esModule, undefined);