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

Vite 4.4.10 - iife modules that import certain libraries break at runtime #14537

Closed
7 tasks done
kadoshms opened this issue Oct 4, 2023 · 2 comments · Fixed by #14539
Closed
7 tasks done

Vite 4.4.10 - iife modules that import certain libraries break at runtime #14537

kadoshms opened this issue Oct 4, 2023 · 2 comments · Fixed by #14539
Labels
feat: library mode p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release

Comments

@kadoshms
Copy link

kadoshms commented Oct 4, 2023

Describe the bug

Since this commit was introduced as part of 4.4.10, iife modules that import certain libraries started breaking on runtime with exceptions such as:

Uncaught SyntaxError: Illegal return statement (at

In our case, we used the qs library - https://www.npmjs.com/package/qs, simply importing them into an IIFE module, and even printing the library contents reproduces the issue.

In particular, the issue comes from the following manipulation on the code during build:

                    const esbuildHelpers = esbuildCode.slice(0, contentIndex);
                    res.code = esbuildCode
                        .slice(contentIndex)
                        .replace(`"use strict";`, `"use strict";` + esbuildHelpers);

I guess that since qs compiles with commonjs might be the issue.
However, we have been using this library with our IIFE modules for months now, and this issue started popping out, unfortunately on runtime, only since we upgraded to 4.4.10.

Reproduction

https://stackblitz.com/edit/vitejs-vite-su78z8?file=main.js,vite.config.ts,index.ts,index.html,package.json,node_modules%2Fvite%2Fdist%2Fnode%2Fchunks%2Fdep-3bba9c7e.js&terminal=dev

Steps to reproduce

Simply run the project.
To "fix", remove the console.log from index.ts

System Info

This reproduces easily on the StackBlitz, but anyway:


  System:
    OS: macOS 13.6
    CPU: (12) arm64 Apple M2 Pro
    Memory: 1.71 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.20.1 - ~/.nvm/versions/node/v16.20.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.1/bin/npm
    pnpm: 8.6.10 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 117.0.5938.132
    Safari: 17.0
  npmPackages:
    @vitejs/plugin-react: ^4.1.0 => 4.1.0 
    vite: ^4.4.10 => 4.4.10

Used Package Manager

yarn

Logs

No response

Validations

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release feat: library mode labels Oct 5, 2023
@bluwy
Copy link
Member

bluwy commented Oct 5, 2023

Vite 4.4.11 is published which reverts 128ad8f, will keep it open for now as the bug still exist in Vite 5.

@kadoshms
Copy link
Author

kadoshms commented Oct 5, 2023

Thanks for that @bluwy

@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: library mode p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants