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

dev server fails to load workers and wasm files from package dependencies, preview and build work fine #13314

Closed
7 tasks done
tantaman opened this issue May 23, 2023 · 3 comments
Labels
duplicate This issue or pull request already exists

Comments

@tantaman
Copy link

tantaman commented May 23, 2023

Describe the bug

I have a package on npm which starts a SharedWorker and loads a WASM file. When users install this package via npm, vite dev mode is unable to find the worker scripts.

If the users do vite preview / vite build, however, everything works as expected.

I've created a minimal repro (~10 lines of code) to demonstrate the issue.

Error text (for searchability): Failed to fetch a worker script

Reproduction

https://github.com/tantaman/vite-worker-repro

Steps to reproduce

  1. git clone [email protected]:tantaman/vite-worker-repro.git
  2. pnpm install
  3. pnpm dev

Open the window, you'll get an error in your console that the worker failed to load.

Screenshot 2023-05-23 at 10 08 02 AM

The worker is loaded from here: https://github.com/tantaman/vite-worker-repro/blob/47637a3d72a3a187c3110a11534c3f1177edf049/src/main.ts#L7-L9

The worker package is here: https://github.com/tantaman/vite-worker-repro/blob/47637a3d72a3a187c3110a11534c3f1177edf049/worker-package/src/index.js#L2-L12

Running pnpm preview and everything will work fine.

Screenshot 2023-05-23 at 10 08 40 AM

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 160.59 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.0.1 - ~/.nvm/versions/node/v19.0.1/bin/node
    Yarn: 3.5.0 - ~/.nvm/versions/node/v19.0.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v19.0.1/bin/npm
    Watchman: 2023.02.27.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 113.0.5672.126
    Firefox: 112.0.1
    Safari: 16.2
  npmPackages:
    vite: ^4.3.2 => 4.3.2

Used Package Manager

pnpm

Logs

Click to expand!
  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help
  vite:html-fallback Rewriting GET / to /index.html +0ms
  vite:resolve 2.05ms /src/main.ts -> /Users/tantaman/vlcn/vite-repro/src/main.ts +0ms
  vite:time 21.01ms /index.html +0ms
  vite:load 1.57ms [fs] /src/main.ts +0ms
  vite:resolve 0.21ms /@vite/client -> /Users/tantaman/vlcn/vite-repro/node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/client.mjs +18ms
  vite:load 1.62ms [fs] /@vite/client +17ms
  vite:resolve 0.07ms @vite/env -> /Users/tantaman/vlcn/vite-repro/node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/env.mjs +6ms
  vite:import-analysis 1.77ms [1 imports rewritten] node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/client.mjs +0ms
  vite:transform 3.31ms /@vite/client +0ms
  vite:time 7.49ms /@vite/client +25ms
  vite:load 0.84ms [fs] /node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/env.mjs +5ms
  vite:import-analysis 0.07ms [no imports] node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/env.mjs +1ms
  vite:transform 0.49ms /node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/env.mjs +1ms
  vite:cache [304] /node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/env.mjs +0ms
  vite:time 0.20ms /node_modules/.pnpm/[email protected]/node_modules/vite/dist/client/env.mjs +5ms
  vite:resolve 0.64ms ./style.css -> /Users/tantaman/vlcn/vite-repro/src/style.css +16ms
  vite:resolve 0.68ms ./typescript.svg -> /Users/tantaman/vlcn/vite-repro/src/typescript.svg +1ms
  vite:resolve 0.70ms ./counter.ts -> /Users/tantaman/vlcn/vite-repro/src/counter.ts +0ms
  vite:resolve 0.85ms vite-repro-worker -> /Users/tantaman/vlcn/vite-repro/node_modules/.vite/deps/vite-repro-worker.js?v=9677e595 +0ms
  vite:optimize-deps load /Users/tantaman/vlcn/vite-repro/node_modules/.vite/deps/vite-repro-worker.js +0ms
  vite:load 0.24ms [plugin] /src/typescript.svg +16ms
  vite:import-analysis 1.84ms [5 imports rewritten] src/main.ts +16ms
  vite:load 0.29ms [plugin] /vite.svg +1ms
  vite:transform 37.72ms /src/main.ts +16ms
  vite:time 23.06ms /src/main.ts +12ms
  vite:import-analysis 0.01ms [no imports] src/typescript.svg +0ms
  vite:transform 0.24ms /src/typescript.svg +0ms
  vite:import-analysis 0.01ms [no imports] /vite.svg +0ms
  vite:transform 0.20ms /vite.svg +0ms
  vite:load 0.96ms [fs] /src/counter.ts +0ms
  vite:load 1.14ms [plugin] /node_modules/.vite/deps/vite-repro-worker.js?v=9677e595 +0ms
  vite:import-analysis 0.02ms [no imports] node_modules/.vite/deps/vite-repro-worker.js?v=9677e595 +2ms
  vite:transform 1.94ms /node_modules/.vite/deps/vite-repro-worker.js?v=9677e595 +2ms
  vite:load 3.26ms [fs] /src/style.css +2ms
  vite:hmr [self-accepts] src/style.css +0ms
  vite:import-analysis 0.14ms [0 imports rewritten] src/style.css +1ms
  vite:transform 0.58ms /src/style.css +1ms
  vite:import-analysis 0.02ms [no imports] src/counter.ts +1ms
  vite:transform 3.43ms /src/counter.ts +1ms
  vite:cache [304] /src/style.css +16ms
  vite:time 0.11ms /src/style.css +4ms
  vite:cache [304] /src/typescript.svg +0ms
  vite:time 0.09ms /src/typescript.svg?import +0ms
  vite:cache [304] /vite.svg +1ms
  vite:time 0.05ms /vite.svg?import +1ms
  vite:cache [304] /src/counter.ts +0ms
  vite:time 0.09ms /src/counter.ts +0ms
  vite:resolve 0.14ms /node_modules/.vite/deps/worker.js?type=module&worker_file -> /Users/tantaman/vlcn/vite-repro/node_modules/.vite/deps/worker.js?type=module&worker_file +10ms
  vite:optimize-deps load /Users/tantaman/vlcn/vite-repro/node_modules/.vite/deps/worker.js +10ms
  vite:time 0.22ms /vite.svg +4ms
  vite:time 0.29ms /src/typescript.svg +1ms
  vite:time 1.70ms /node_modules/.vite/deps/worker.js?type=module&worker_file +0ms
  vite:time 6.80ms /vite.svg +184ms
  vite:time 1.30ms /node_modules/.vite/deps/vite-repro-worker.js.map +3s

Validations

@tantaman tantaman changed the title dev bundler fails to load workers and wasm files, preview and build work fine dev server fails to load workers and wasm files from package dependencies, preview and build work fine May 23, 2023
@tantaman
Copy link
Author

tantaman commented May 23, 2023

The minimal repro that only loads a worker is inexplicably working now.

Let me update it to include loading of WASM files which is still broken.


update: nope, vite is definitely still broken. Opening the repro in a new icognito window fails.

@patak-dev patak-dev added p3-minor-bug An edge case that only affects very specific usage (priority) feat: deps optimizer Esbuild Dependencies Optimization and removed pending triage labels May 24, 2023
@patak-dev
Copy link
Member

It looks like the worker.js entry point in the vite-repro-worker package isn't optimized by esbuild as it isn't imported by your source code. The file doesn't end up node_modules/.vite/deps/.

Until this is fixed, as a workaround, you can exclude this dependency from being optimized during dev. See your repro working at https://stackblitz.com/edit/github-nj3h7r?file=vite.config.ts

export default defineConfig({
    optimizeDeps: {
        exclude: ['vite-repro-worker']
    }
});

@patak-dev
Copy link
Member

Thanks @sapphi-red for the pointer! This issue is a duplicate of #8427. Let's keep the discussion there.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 8, 2023
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed p3-minor-bug An edge case that only affects very specific usage (priority) feat: deps optimizer Esbuild Dependencies Optimization labels Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants