question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`vite dev` doesn't copy assets to `node_modules/.vite/deps` via `new URL()` support in worker scripts

See original GitHub issue

Describe the bug

vite dev doesn’t copy assets to node_modules/.vite/deps via new URL() support in worker scripts

Manually copying the missing assets to node_modules/.vite/deps seems to fix the problem as a workaround.

Reproduction

https://github.com/schickling-test/2022-nov-vite-worker-dev-repro

Steps to reproduce

Unfortunately due to some Stackblitz WASM limitations, it doesn’t work on Stackblitz yet.

Setup

git clone git@github.com:schickling-test/2022-nov-vite-worker-dev-repro.git
2022-nov-vite-worker-dev-repro
npm install

Repro bug: dev not working

npm run dev
# dev console should now show WASM errors and the network monitor should show 404s

CleanShot 2022-11-02 at 10 45 43@2x

Repro workaround: dev working

npm run dev
npm run fix-dev # run in another terminal
# things should work now

CleanShot 2022-11-02 at 10 47 17@2x

Repro prod build working

npm run build
npm run preview # uses netlify cli to use the needed HTTP headers
# things should work now

CleanShot 2022-11-02 at 10 37 14@2x

System Info

System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 47.81 MB / 32.00 GB
    Shell: 3.4.1 - /Users/schickling/.nix-profile/bin/fish
  Binaries:
    Node: 16.16.0 - ~/.nix-profile/bin/node
    Yarn: 1.22.18 - ~/.nix-profile/bin/yarn
    npm: 8.11.0 - ~/.nix-profile/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Chrome Canary: 109.0.5396.0
    Firefox: 100.0
    Safari: 16.1
  npmPackages:
    vite: ^3.2.2 => 3.2.2

Used Package Manager

npm

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sapphi-redcommented, Dec 2, 2022

I guess replacing const wasmUrl = new URL('sqlite3.wasm', import.meta.url).href with import wasmUrl from 'sqlite3.wasm?url' would work for Vite. But that will break other bundlers and nodejs.

0reactions
schicklingcommented, Dec 3, 2022

Thanks a lot for your comment, I’ll give the exclude option another try.

Using exclude: ['sqlite-wasm-esm'] seems to indeed work now as a workaround. Closing as duplicate of https://github.com/vitejs/vite/issues/8427.

Thanks for your help @sapphi-red

Read more comments on GitHub >

github_iconTop Results From Across the Web

new URL(foo, import.meta.url) doesn't work when dependency ...
In Vite, after esbuild optimize third party, import.meta.url cannot be optimize succeed. Ref Vite Docs, even if set build.target to es2020 ...
Read more >
Features | Vite
Rewrite the imports to valid URLs like /node_modules/.vite/deps/my-dep.js?v=f3sf2ebd so that the browser can import them properly. Dependencies are Strongly ...
Read more >
Vue3 + Vite + Vuestic: Running in Dev Server but Blank White ...
I found on stack overflow that this may be because of the static paths in production by vite . But, this problem I...
Read more >
vite exports is not defined | The AI Search Engine You Control
error: exports is not defined when using ViteDevServer. ... vite:config 'vite:worker', vite:config 'vite:worker-import-meta-url', vite:config 'vite:asset', ...
Read more >
How to Install and Use Vite in Your Web Projects
Vite uses native browser ES imports to enable support for modern browsers without a build process. Vite consists of two major parts: The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found