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 v6.0.7 breaks vite-plugin-top-level-await #19160

Closed
7 tasks done
ocavue opened this issue Jan 8, 2025 · 1 comment
Closed
7 tasks done

vite v6.0.7 breaks vite-plugin-top-level-await #19160

ocavue opened this issue Jan 8, 2025 · 1 comment

Comments

@ocavue
Copy link
Contributor

ocavue commented Jan 8, 2025

Describe the bug

After updating vite from v6.0.6 to v6.0.7, vite-plugin-top-level-await doesn't work anymore. vite-plugin-top-level-await is required by vite-plugin-wasm and many other wasm packages.

Reproduction

https://github.com/issueset/vite-plugin-top-level-await-regression

Steps to reproduce

Here is a minimal example to show the error with vite v6.0.7:

$ git clone https://github.com/issueset/vite-plugin-top-level-await-regression --branch 607 607

$ cd 607

$ pnpm install
+ vite 6.0.7
+ vite-plugin-top-level-await 1.4.4

$ pnpm run build

x Build failed in 44ms
error during build:
[vite:esbuild-transpile] Transform failed with 1 error:
assets/index-!~{001}~.js:45:0: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
43 |  console.log("START_TOP_LEVEL_AWAIT");
44 |  let number1 = Math.random();
45 |  await new Promise((resolve) => setTimeout(resolve, 1000));
   |  ^
46 |  let number2 = Math.random();
47 |  console.log("END_TOP_LEVEL_AWAIT");

Here is the same example with vite v6.0.6, which works fine:

$ git clone https://github.com/issueset/vite-plugin-top-level-await-regression --branch 606 606

$ cd 606 

$ pnpm install
+ vite 6.0.6
+ vite-plugin-top-level-await 1.4.4

$ pnpm run build
✓ built in 58ms

System Info

System:
    OS: macOS 15.1.1
    CPU: (8) arm64 Apple M2
    Memory: 66.14 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.18.1 - /opt/homebrew/opt/node@20/bin/node
    Yarn: 1.22.21 - /opt/homebrew/opt/node@18/bin/yarn
    npm: 10.8.2 - /opt/homebrew/opt/node@20/bin/npm
    pnpm: 8.15.9 - /opt/homebrew/opt/node@18/bin/pnpm
    bun: 1.1.26 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 122.1.63.169
    Chrome: 131.0.6778.264
    Chrome Canary: 134.0.6944.0
    Safari: 18.1.1
    Safari Technology Preview: 18.2
  npmPackages:
    vite: 6.0.7 => 6.0.7

Used Package Manager

pnpm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 9, 2025

vite-plugin-top-level-await is mutating config.build.target = 'esnext' during configResolved() hook https://github.com/Menci/vite-plugin-top-level-await/blob/ae432b6823d6608b0de8c607bf14c3025c76e80a/src/index.ts#L56-L60 and this is not a supported usage, which then got broken by the change like #19025

I think vite-plugin-top-level-await can use config() hook instead to override config properly.

        config(config, env) {
            if (env.command === 'build') {
                buildTarget = config.build.target;
                config.build.target = "esnext";
            }
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants