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

iife code generated by vite3 is not working #9318

Closed
7 tasks done
Jackie1210 opened this issue Jul 23, 2022 · 6 comments · Fixed by rollup/rollup#4588
Closed
7 tasks done

iife code generated by vite3 is not working #9318

Jackie1210 opened this issue Jul 23, 2022 · 6 comments · Fixed by rollup/rollup#4588
Labels
bug: upstream Bug in a dependency of Vite feat: library mode

Comments

@Jackie1210
Copy link

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

@bluwy
Copy link
Member

bluwy commented Jul 23, 2022

Make sense to me. Rollup says that the name should be global, so it should be var instead.

@sapphi-red
Copy link
Member

This seems to be an upstream issue. When generatedCode.preset = 'es2015' is set, rollup outputs the variable with const instead of var.

stackblitz

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite and removed bug labels Jul 23, 2022
@Jackie1210
Copy link
Author

yep,it was okay when i use vite2. I just use umd instead now.

@lukastaegert
Copy link

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

@lukastaegert
Copy link

Fix at rollup/rollup#4588

@sapphi-red
Copy link
Member

Thanks!

Closing as rollup 2.77.1 that includes the fix was released.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2022
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 feat: library mode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants