diff --git a/src/Chunk.ts b/src/Chunk.ts index 2803e1f536e..70ca4c4d850 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -98,9 +98,7 @@ function getGlobalName( graph.warn({ code: 'MISSING_GLOBAL_NAME', guess: module.variableName, - message: `No name was provided for external module '${ - module.id - }' in output.globals – guessing '${module.variableName}'`, + message: `No name was provided for external module '${module.id}' in output.globals – guessing '${module.variableName}'`, source: module.id }); return module.variableName; @@ -1088,7 +1086,10 @@ export default class Chunk { } } } - if (module.isEntryPoint) { + if ( + module.isEntryPoint || + module.dynamicallyImportedBy.some(importer => importer.chunk !== this) + ) { const map = module.getExportNamesByVariable(); for (const exportedVariable of map.keys()) { this.exports.add(exportedVariable); diff --git a/test/function/samples/chunking-duplicate-reexport/_config.js b/test/function/samples/chunking-duplicate-reexport/_config.js new file mode 100644 index 00000000000..811122ba995 --- /dev/null +++ b/test/function/samples/chunking-duplicate-reexport/_config.js @@ -0,0 +1,8 @@ +const assert = require('assert'); + +module.exports = { + description: 'handles duplicate reexports when using dynamic imports', + exports(exports) { + return exports.then(result => assert.deepStrictEqual(result, [{ answer: 42 }, { answer: 42 }])); + } +}; diff --git a/test/function/samples/chunking-duplicate-reexport/chunk1.js b/test/function/samples/chunking-duplicate-reexport/chunk1.js new file mode 100644 index 00000000000..f607280ef4d --- /dev/null +++ b/test/function/samples/chunking-duplicate-reexport/chunk1.js @@ -0,0 +1 @@ +export { answer } from './lib.js'; diff --git a/test/function/samples/chunking-duplicate-reexport/chunk2.js b/test/function/samples/chunking-duplicate-reexport/chunk2.js new file mode 100644 index 00000000000..f607280ef4d --- /dev/null +++ b/test/function/samples/chunking-duplicate-reexport/chunk2.js @@ -0,0 +1 @@ +export { answer } from './lib.js'; diff --git a/test/function/samples/chunking-duplicate-reexport/lib.js b/test/function/samples/chunking-duplicate-reexport/lib.js new file mode 100644 index 00000000000..64a32fd291e --- /dev/null +++ b/test/function/samples/chunking-duplicate-reexport/lib.js @@ -0,0 +1 @@ +export const answer = 42; diff --git a/test/function/samples/chunking-duplicate-reexport/main.js b/test/function/samples/chunking-duplicate-reexport/main.js new file mode 100644 index 00000000000..fa49840438d --- /dev/null +++ b/test/function/samples/chunking-duplicate-reexport/main.js @@ -0,0 +1 @@ +export default Promise.all([import('./chunk1.js'), import('./chunk2.js')]);