Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic imports are not tree-shaken #11080

Closed
7 tasks done
fabiospampinato opened this issue Nov 25, 2022 · 2 comments
Closed
7 tasks done

Dynamic imports are not tree-shaken #11080

fabiospampinato opened this issue Nov 25, 2022 · 2 comments
Labels
bug: upstream Bug in a dependency of Vite enhancement New feature or request has workaround

Comments

@fabiospampinato
Copy link

fabiospampinato commented Nov 25, 2022

Describe the bug

Static imports are tree-shaken, so should statically analyzable dynamic imports.

Reproduction

https://github.com/vitejs/vite/files/10094628/repro.zip

Steps to reproduce

  • npm i
  • npm run build
  • Look into the dist folder, and you'll see that not only the "visit" function is bundled when using dynamic imports.

System Info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 981.67 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.0/bin/npm

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

This is not supported by rollup (rollup/rollup#3417, rollup/rollup#3447) (repro with rollup@2.79.1, repro with rollup@3.4.0).

The workaround would be to create an facade module like:

// foo.js
import('./bar-facade').then(({ bar }) => bar())

// bar-facade.js
export { bar } from './bar'

// bar.js
export const bar = ''
export const bar1 = ''

@sapphi-red
Copy link
Member

Closing as this is now supported by rollup 🎉 (repro with rollup@3.21.0)

@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug: upstream Bug in a dependency of Vite enhancement New feature or request has workaround
Projects
None yet
Development

No branches or pull requests

2 participants