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

🚨 [REGRESSION][6.0.11 -> 6.1.0] Building with Web Worker fails #19458

Closed
7 tasks done
repulsio opened this issue Feb 18, 2025 · 5 comments · Fixed by #19462
Closed
7 tasks done

🚨 [REGRESSION][6.0.11 -> 6.1.0] Building with Web Worker fails #19458

repulsio opened this issue Feb 18, 2025 · 5 comments · Fixed by #19462
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release

Comments

@repulsio
Copy link

Describe the bug

This used to build successfully in version 6.0.11. Started failing in 6.1.0.

Code:

const worker = new Worker(new URL('./worker', import.meta.url));

Build:

vite build

✓ 30 modules transformed.
x Build failed in 136ms
error during build:
[vite:worker-import-meta-url] Expected ',', got ':'
file: /home/nonroot/app/browser/src/worker/singleton.ts
    at getRollupError (file:///home/nonroot/app/browser/node_modules/rollup/dist/es/shared/parseAst.js:397:41)
    at convertProgram (file:///home/nonroot/app/browser/node_modules/rollup/dist/es/shared/parseAst.js:1085:26)
    at parseAstAsync (file:///home/nonroot/app/browser/node_modules/rollup/dist/es/shared/parseAst.js:2071:106)
    at async parseWorkerOptions (file:///home/nonroot/app/browser/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:46636:23)
    at async getWorkerType (file:///home/nonroot/app/browser/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:46675:22)
    at async Object.transform (file:///home/nonroot/app/browser/node_modules/vite/dist/node/chunks/dep-CfG9u7Cn.js:46721:30)
    at async transform (file:///home/nonroot/app/browser/node_modules/rollup/dist/es/shared/node-entry.js:20689:16)
    at async ModuleLoader.addModuleSource (file:///home/nonroot/app/browser/node_modules/rollup/dist/es/shared/node-entry.js:20902:36)

Reproduction

Please see code below

Steps to reproduce

Code:

const worker = new Worker(new URL('./worker', import.meta.url));

Build:

vite build

System Info

System:
    OS: Linux 6.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (10) arm64 unknown
    Memory: 6.23 GB / 7.65 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 20.13.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.1 - /usr/local/bin/npm
  npmPackages:
    vite: ^6.1.0 => 6.1.0

Used Package Manager

npm

Logs

No response

Validations

@repulsio repulsio changed the title 🚨 [REGRESSION][6.0.11 -> 6.1.0] Building with Web Worker fails 🚨 🚨 [REGRESSION][6.0.11 -> 6.1.0] Building with Web Worker fails Feb 18, 2025
@hi-ogawa
Copy link
Collaborator

I couldn't reproduce https://stackblitz.com/edit/vitejs-vite-lrkn1iir?file=src%2Fmain.js Please provide a full code which can reproduce your issue.

Copy link

Hello @repulsio. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@repulsio
Copy link
Author

repulsio commented Feb 18, 2025

@hi-ogawa, thank you for starting the stackblitz. I've added some changes to reproduce the issue:

https://stackblitz.com/edit/vitejs-vite-jno6nvaz?file=src%2Fmain.js

Turns out that wrapping it inside of an IIFE and running postMessage() causes the issue for some reason

Also it's really strange how commenting out postMessage() (but keeping the IIFE) causes the build to succeed

@hi-ogawa hi-ogawa added pending triage p3-minor-bug An edge case that only affects very specific usage (priority) and removed needs reproduction pending triage labels Feb 18, 2025
@hi-ogawa
Copy link
Collaborator

It's likely a regression of #19010. This simple case should bail out early here, but some odd string });\n} ended up passed to parseAstAsync instead.

const endIndex = findClosingParen(clean, i)
// case: ') ... ,' mean no worker options params
if (commaIndex > endIndex) {
return 'classic'
}

@sapphi-red sapphi-red added the regression The issue only appears after a new release label Feb 18, 2025
@repulsio
Copy link
Author

Thank you so much, @hi-ogawa !

@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: web workers 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