question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`iife` code generated by vite3 is not working

See original GitHub issue

Describe the bug

I was building a lib generated in iife mode, and it is not working as soon as i put it on cdn.

image

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
lukastaegertcommented, Jul 26, 2022

Fix at rollup/rollup#4588

3reactions
lukastaegertcommented, Jul 24, 2022

Interesting. While const does 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found