Skip to content

Unexpected hoisting when output.hoistTransitiveImports = true and treeshake.moduleSideEffects = false | 'no-external' #6111

Description

@stipsan

Rollup Version

v4.50.2

Operating System (or Browser)

macOS 15.5

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=4.50.2&shareable=eyJleGFtcGxlIjpudWxsLCJtb2R1bGVzIjpbeyJjb2RlIjoiZXhwb3J0IHtjcmVhdGVDbGllbnQsIHVuc3RhYmxlX19hZGFwdGVyLCB1bnN0YWJsZV9fZW52aXJvbm1lbnR9IGZyb20gJ0BzYW5pdHkvY2xpZW50J1xuXG4vLyBTb21laG93IHVuY29tbWVudGluZyB0aGUgYmVsb3cgd2lsbCBzdG9wIHRoZSBob2lzdGluZ1xuLy8gZXhwb3J0IGNvbnN0IGZvbyA9ICdiYXInIiwiaXNFbnRyeSI6dHJ1ZSwibmFtZSI6Im1haW4uanMifSx7ImNvZGUiOiJleHBvcnQge3VzZVByZXNlbnRhdGlvblF1ZXJ5fSBmcm9tICdAc2FuaXR5L25leHQtbG9hZGVyL2hvb2tzJ1xuZXhwb3J0IHt1c2VPcHRpbWlzdGljfSBmcm9tICdAc2FuaXR5L3Zpc3VhbC1lZGl0aW5nL3JlYWN0J1xuXG4vLyBVbmNvbW1lbnRpbmcgdGhpcyBhbHNvIHN0b3BzIHRoZSBpbXBvcnQgaG9pc3Rpbmdcbi8vIGV4cG9ydCBjb25zdCBmb28gPSAnYmFyJyIsImlzRW50cnkiOnRydWUsIm5hbWUiOiJob29rcy5qcyJ9XSwib3B0aW9ucyI6eyJvdXRwdXQiOnsiZm9ybWF0IjoiZXMiLCJob2lzdFRyYW5zaXRpdmVJbXBvcnRzIjpmYWxzZX0sInByZXNlcnZlRW50cnlTaWduYXR1cmVzIjoic3RyaWN0IiwidHJlZXNoYWtlIjoic21hbGxlc3QifX0=

Expected Behaviour

Since output.hoistTransitiveImports are false, and preserveEntrySignatures are 'strict', there should be no hoisting of imports.
Setting treeshake.moduleSideEffects to false or 'no-external' should only treeshake, no matter if the entries are purely re-exports from other packages, or a mixture.

Actual Behaviour

In the repro, the output main.js should not have the import '@sanity/next-loader/hooks' and import '@sanity/visual-editing/react' bare imports, they are only used by the hooks.js output.

What's even weirder is that it seems connected to chunks that only re-export from other chunks. If any other export is added, like export const foo = 'bar', then the hoisting no longer happens.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions