Skip to content
Closed
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 Nov 28, 2019
commit 42f7d59b8d00c7fdf1ccfd4b178c98b7dcbf24de
14 changes: 6 additions & 8 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,6 @@ Module._extensions['.js'] = function(module, filename) {
const basename = parentPath &&
path.basename(filename) === path.basename(parentPath) ?
filename : path.basename(filename);

const warningMsg =
'require() of ES modules is not supported.\nrequire() of ' +
`${filename} ${parentPath ? `from ${module.parent.filename} ` : ''}` +
Expand All @@ -1212,19 +1211,18 @@ Module._extensions['.js'] = function(module, filename) {
'files in that package scope as ES modules.\nInstead rename ' +
`${basename} to end in .cjs, change the requiring code to use ` +
'import(), or remove "type": "module" from ' +
`${path.resolve(pkg.path, 'package.json')}.\n` +
err.message;

// The error message should be (in this case) the as the warning.
// https://github.com/nodejs/node/issues/30599
err.message = warningMsg;
`${path.resolve(pkg.path, 'package.json')}.\n`;
process.emitWarning(
Comment thread
juanarbol marked this conversation as resolved.
Outdated
warningMsg,
warningMsg + err.message,
undefined,
undefined,
undefined,
true
);

// The error message should be (in this case) the as the warning.
// https://github.com/nodejs/node/issues/30599
err.message += `\n${warningMsg}`;
warnRequireESM = false;
}
throw err;
Expand Down