Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixup! module: warn on using unfinished circular dependency
  • Loading branch information
addaleax committed Oct 11, 2019
commit 3ba43138c35f91a097522c6391830fa842ac7dee
7 changes: 6 additions & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,12 @@ const PublicObjectPrototype = global.Object.prototype;

function getExportsForCircularRequire(module) {
if (module.exports &&
Object.getPrototypeOf(module.exports) === PublicObjectPrototype) {
Object.getPrototypeOf(module.exports) === PublicObjectPrototype &&
// Exclude transpiled ES6 modules / TypeScript code because those may
// employ unusual patterns for accessing 'module.exports'. That should be
// okay because ES6 modules have a different approach to circular
// dependencies anyway.
!module.exports.__esModule) {
// This is later unset once the module is done loading.
Object.setPrototypeOf(module.exports, CircularRequirePrototypeWarningProxy);
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/cycles/warning-esm-transpiled-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Object.defineProperty(exports, "__esModule", { value: true });
require('./warning-esm-transpiled-b.js');
1 change: 1 addition & 0 deletions test/fixtures/cycles/warning-esm-transpiled-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./warning-esm-transpiled-a.js').missingPropESM;
5 changes: 5 additions & 0 deletions test/parallel/test-module-circular-dependency-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ assert.strictEqual(Object.getPrototypeOf(requiredWithModuleExportsOverridden),
const classExport =
require(fixtures.path('cycles', 'warning-moduleexports-class-a.js'));
assert.strictEqual(Object.getPrototypeOf(classExport).name, 'Parent');

// If module.exports.__esModule is set, no warning should be emitted.
const esmTranspiledExport =
require(fixtures.path('cycles', 'warning-esm-transpiled-a.js'));
assert.strictEqual(esmTranspiledExport.__esModule, true);