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
Next Next commit
fixup
  • Loading branch information
juanarbol committed Dec 4, 2019
commit 46b04d53b3e31fbcdb1900f70a6f8324cd78ba75
7 changes: 5 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,10 @@ E('ERR_OUT_OF_RANGE',
return msg;
}, RangeError);
E('ERR_REQUIRE_ESM',
(filename, parentPath = null, packageJsonPath = null, basename = null) => {
(filename, parentPath = null, packageJsonPath = null) => {
const path = require('path');
const basename = path.basename(filename) === path.basename(parentPath) ?
Comment thread
juanarbol marked this conversation as resolved.
Outdated
filename : path.basename(filename);
let msg = `Must use import to load ES Module: ${filename}\n`;
Comment thread
juanarbol marked this conversation as resolved.
Outdated
if (parentPath && packageJsonPath) {
msg +=
Expand All @@ -1138,7 +1141,7 @@ E('ERR_REQUIRE_ESM',
return msg;
}
return msg;
}, Error);
}, Error);
E('ERR_SCRIPT_EXECUTION_INTERRUPTED',
'Script execution was interrupted by `SIGINT`', Error);
E('ERR_SERVER_ALREADY_LISTEN',
Expand Down
4 changes: 1 addition & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,7 @@ Module._extensions['.js'] = function(module, filename) {
if (pkg && pkg.data && pkg.data.type === 'module') {
const parentPath = module.parent && module.parent.filename;
const packageJsonPath = path.resolve(pkg.path, 'package.json');
const basename = path.basename(filename) === path.basename(parentPath) ?
filename : path.basename(filename);
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath, basename);
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
}
}
const content = fs.readFileSync(filename, 'utf8');
Expand Down