Skip to content

Commit

Permalink
Missing exports errors now print the importing module (#3401)
Browse files Browse the repository at this point in the history
* Missing exports errors now print the importing module

Prior to this change, we only printed the imported module
that failed, with no context on which module was attempting
the import. This could be difficult to debug in large codebases,
especially when importing commonly-used modules.

* rephrase missing export message

The phrasing attempts to match the "imported by" style
elsewhere in the codebase

* Tests now expect new missing export message format

* Use relative module id when displaying missing export message
  • Loading branch information
timiyay committed Mar 6, 2020
1 parent baf382a commit 1e6284f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Module.ts
Expand Up @@ -157,7 +157,9 @@ function handleMissingExport(
return importingModule.error(
{
code: 'MISSING_EXPORT',
message: `'${exportName}' is not exported by ${relativeId(importedModule)}`,
message: `'${exportName}' is not exported by ${relativeId(
importedModule
)}, imported by ${relativeId(importingModule.id)}`,
url: `https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module`
},
importerStart!
Expand Down
Expand Up @@ -16,7 +16,7 @@ module.exports = {
file: path.resolve(__dirname, 'dep2.js'),
line: 1
},
message: "'doesNotExist' is not exported by dep1.js",
message: "'doesNotExist' is not exported by dep1.js, imported by dep2.js",
pos: 9,
url: 'https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module',
watchFiles: [
Expand Down
2 changes: 1 addition & 1 deletion test/function/samples/default-not-reexported/_config.js
Expand Up @@ -4,7 +4,7 @@ module.exports = {
description: 'default export is not re-exported with export *',
error: {
code: 'MISSING_EXPORT',
message: `'default' is not exported by foo.js`,
message: `'default' is not exported by foo.js, imported by main.js`,
pos: 7,
watchFiles: [
path.resolve(__dirname, 'main.js'),
Expand Down
Expand Up @@ -20,7 +20,7 @@ module.exports = {
},
error: {
code: 'MISSING_EXPORT',
message: `'default' is not exported by empty.js`,
message: `'default' is not exported by empty.js, imported by main.js`,
pos: 44,
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'empty.js')],
loc: {
Expand Down
Expand Up @@ -4,7 +4,7 @@ module.exports = {
description: 'marking an imported, but unexported, identifier should throw',
error: {
code: 'MISSING_EXPORT',
message: `'default' is not exported by empty.js`,
message: `'default' is not exported by empty.js, imported by main.js`,
pos: 7,
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'empty.js')],
loc: {
Expand Down
2 changes: 1 addition & 1 deletion test/function/samples/reexport-missing-error/_config.js
Expand Up @@ -4,7 +4,7 @@ module.exports = {
description: 'reexporting a missing identifier should print an error',
error: {
code: 'MISSING_EXPORT',
message: `'foo' is not exported by empty.js`,
message: `'foo' is not exported by empty.js, imported by main.js`,
pos: 9,
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'empty.js')],
loc: {
Expand Down

0 comments on commit 1e6284f

Please sign in to comment.