Skip to content
Prev Previous commit
Revert "module: improve named cjs import errors"
This reverts commit 22f700c.
  • Loading branch information
ctavan committed Jan 29, 2021
commit 533560f781a0110d9f391dd6e7b37f01847c9443
24 changes: 8 additions & 16 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ class ModuleJob {
}
jobsInGraph.add(moduleJob);
const dependencyJobs = await moduleJob.linked;
return PromiseAll(
new SafeArrayIterator(
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)
)
);
return PromiseAll(new SafeArrayIterator(
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)));
};
await addJobsToDependencyGraph(this);

Expand All @@ -174,19 +171,15 @@ class ModuleJob {
}
} catch (e) {
decorateErrorStack(e);
if (
StringPrototypeIncludes(e.message, ' does not provide an export named')
) {
if (StringPrototypeIncludes(e.message,
' does not provide an export named')) {
const splitStack = StringPrototypeSplit(e.stack, '\n');
const parentFileUrl = splitStack[0];
const { 1: childSpecifier, 2: name } = StringPrototypeMatch(
e.message,
/module '(.*)' does not provide an export named '(.+)'/
);
const childFileURL = await this.loader.resolve(
childSpecifier,
parentFileUrl
);
/module '(.*)' does not provide an export named '(.+)'/);
const childFileURL =
await this.loader.resolve(childSpecifier, parentFileUrl);
const format = await this.loader.getFormat(childFileURL);
if (format === 'commonjs') {
const [, fileUrl, lineNumber] = StringPrototypeMatch(
Expand All @@ -197,8 +190,7 @@ class ModuleJob {
fileURLToPath(fileUrl),
Number(lineNumber)
);
e.message =
`Named export '${name}' not found. The requested module` +
e.message = `Named export '${name}' not found. The requested module` +
` '${childSpecifier}' is a CommonJS module, which may not support` +
' all module.exports as named exports.\nCommonJS modules can ' +
'always be imported via the default export, for example using:' +
Expand Down