From 1e6284fb4d9300bb2551d28a60b2aea5b104496c Mon Sep 17 00:00:00 2001 From: timiyay Date: Fri, 6 Mar 2020 16:29:37 +1100 Subject: [PATCH] Missing exports errors now print the importing module (#3401) * 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 --- src/Module.ts | 4 +++- test/function/samples/circular-missed-reexports-2/_config.js | 2 +- test/function/samples/default-not-reexported/_config.js | 2 +- .../_config.js | 2 +- test/function/samples/import-of-unexported-fails/_config.js | 2 +- test/function/samples/reexport-missing-error/_config.js | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Module.ts b/src/Module.ts index 2e194f552e9..c7dd98a9d4e 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -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! diff --git a/test/function/samples/circular-missed-reexports-2/_config.js b/test/function/samples/circular-missed-reexports-2/_config.js index df2bf9004dd..e17a190410c 100644 --- a/test/function/samples/circular-missed-reexports-2/_config.js +++ b/test/function/samples/circular-missed-reexports-2/_config.js @@ -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: [ diff --git a/test/function/samples/default-not-reexported/_config.js b/test/function/samples/default-not-reexported/_config.js index 947141dbbbb..be866dd0b30 100644 --- a/test/function/samples/default-not-reexported/_config.js +++ b/test/function/samples/default-not-reexported/_config.js @@ -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'), diff --git a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js index 23001b3ba56..58c2caa9550 100644 --- a/test/function/samples/error-after-transform-should-throw-correct-location/_config.js +++ b/test/function/samples/error-after-transform-should-throw-correct-location/_config.js @@ -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: { diff --git a/test/function/samples/import-of-unexported-fails/_config.js b/test/function/samples/import-of-unexported-fails/_config.js index 0db25ac0ad5..6f5fa5552b2 100644 --- a/test/function/samples/import-of-unexported-fails/_config.js +++ b/test/function/samples/import-of-unexported-fails/_config.js @@ -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: { diff --git a/test/function/samples/reexport-missing-error/_config.js b/test/function/samples/reexport-missing-error/_config.js index 032dc7b3c7e..5a17f6c2bd5 100644 --- a/test/function/samples/reexport-missing-error/_config.js +++ b/test/function/samples/reexport-missing-error/_config.js @@ -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: {