`iife` code generated by vite3 is not working
See original GitHub issueDescribe the bug
I was building a lib generated in iife mode, and it is not working as soon as i put it on cdn.
Reproduction
https://github.com/Jackie1210/vite-lib-iife-bug-repo
System Info
System:
OS: macOS 11.6
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 438.13 MB / 8.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 18.6.0 - ~/.nvm/versions/node/v18.6.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 8.13.2 - ~/.nvm/versions/node/v18.6.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 103.0.5060.134
Firefox: 102.0
Safari: 15.0
npmPackages:
vite: ^3.0.2 => 3.0.2
Used Package Manager
pnpm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
`iife` code generated by vite3 is not working · vitejs/vite@e66cf69 ...
Next generation frontend tooling. It's fast! Contribute to vitejs/vite development by creating an account on GitHub.
Read more >How to wrap Vite build in IIFE and still have ... - Stack Overflow
The main problem is during minification and mangling there are a lot of global variables created. After injecting my script to the page...
Read more >Build Options - Vite
Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See esbuild docs for more details....
Read more >Fixing Hot Module Reload of Vite App in WSL - YouTube
Is hot reloading not working in your app created with Vite ? For Windows and WSL users polling might the solution to your...
Read more >How to Bundle JavaScript With Rollup — Step-by-Step Tutorial
The code should still work, but you may want to look for a more up-to-date tutorial. ... Rollup is a next-generation JavaScript module...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Fix at rollup/rollup#4588
Interesting. While
constdoes indeed declare variables that are defined in other script scopes, which should be good enough for IIFE, they do not end up on the global object so apparently there is a scope in between. Will need to change this. https://stackblitz.com/edit/web-platform-s6tham?devToolsHeight=33&file=script.js