From e440b4d91bba583f4a07b6bf898bbc4b244b620e Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 30 Jan 2023 06:35:24 +0100 Subject: [PATCH] Show warning also for namespace imports --- src/Chunk.ts | 11 ++++++----- .../_config.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Chunk.ts b/src/Chunk.ts index c5486a8f7ad..21f65ec3eb1 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -1378,12 +1378,13 @@ export default class Chunk { const chunk = this.chunkByModule.get(variable.module as Module); if (chunk !== this) { this.imports.add(variable); - if ( - !(variable instanceof NamespaceVariable && this.outputOptions.preserveModules) && - variable.module instanceof Module - ) { - chunk!.exports.add(variable); + if (variable.module instanceof Module) { this.checkCircularDependencyImport(variable, module); + // When preserving modules, we do not create namespace objects but directly + // use the actual namespaces, which would be broken by this logic. + if (!(variable instanceof NamespaceVariable && this.outputOptions.preserveModules)) { + chunk!.exports.add(variable); + } } } } diff --git a/test/function/samples/circular-namespace-reexport-preserve-modules/_config.js b/test/function/samples/circular-namespace-reexport-preserve-modules/_config.js index 34a4a905bc0..a66f558f911 100644 --- a/test/function/samples/circular-namespace-reexport-preserve-modules/_config.js +++ b/test/function/samples/circular-namespace-reexport-preserve-modules/_config.js @@ -32,6 +32,22 @@ module.exports = { 'Export "*" of module "formatters.js" was reexported through module "index.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "main.js" to point directly to the exporting module or do not use "output.preserveModules" to ensure these modules end up in the same chunk.', reexporter: ID_INDEX }, + { + code: 'CYCLIC_CROSS_CHUNK_REEXPORT', + exporter: ID_FORMATTERS, + id: ID_MAIN, + message: + 'Export "*" of module "formatters.js" was reexported through module "index.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "main.js" to point directly to the exporting module or do not use "output.preserveModules" to ensure these modules end up in the same chunk.', + reexporter: ID_INDEX + }, + { + code: 'CYCLIC_CROSS_CHUNK_REEXPORT', + exporter: ID_FORMATTERS, + id: ID_TYPES, + message: + 'Export "*" of module "formatters.js" was reexported through module "index.js" while both modules are dependencies of each other and will end up in different chunks by current Rollup settings. This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.\nEither change the import in "types.js" to point directly to the exporting module or do not use "output.preserveModules" to ensure these modules end up in the same chunk.', + reexporter: ID_INDEX + }, { code: 'CYCLIC_CROSS_CHUNK_REEXPORT', exporter: ID_TYPES,