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

Dynamic Imports within web workers are broken (browser mode) #6552

Open
6 tasks done
alexlwn123 opened this issue Sep 23, 2024 · 0 comments
Open
6 tasks done

Dynamic Imports within web workers are broken (browser mode) #6552

alexlwn123 opened this issue Sep 23, 2024 · 0 comments

Comments

@alexlwn123
Copy link

alexlwn123 commented Sep 23, 2024

Describe the bug

globalThis.__vitest_broser_runner__ is not accessible within the scope of web workers, so vite's dynamic import wrapping is breaking via:
image

Adding this hack to the top of the worker seems to fix the issue, but it's still a bug nonetheless:

image

Reproduction

I'm struggling to repro on StackBlitz due to browser mode incompatibilities on the web-based IDE.

Here's some links to my open source project where this applies:

To reproduce, start a web worker that contains a dynamic import...

// main.ts
const worker = new Worker(new URL('./worker-file.js', import.meta.url), { type: 'module' })

// ...

// worker-file.js

const asset = await import('any-package-or-file')

System Info

System:
    OS: macOS 14.6.1
    CPU: (10) x64 Apple M1 Max
    Memory: 24.88 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.local/state/fnm_multishells/19453_1726068848957/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 10.8.2 - ~/.local/state/fnm_multishells/19453_1726068848957/bin/npm
    pnpm: 9.4.0 - /usr/local/bin/pnpm
    bun: 1.1.26 - ~/.bun/bin/bun
    Watchman: 2024.05.06.00 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 128.1.69.168
    Safari: 17.6
  npmPackages:
    @vitest/browser: ^2.1.1 => 2.1.1 
    @vitest/coverage-v8: ^2.1.1 => 2.1.1 
    @vitest/ui: ^2.1.1 => 2.1.1 
    vitest: ^2.1.1 => 2.1.1

Used Package Manager

pnpm

Validations

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

1 participant