`new URL(foo, import.meta.url)` doesn't work when dependency was optimized
See original GitHub issueDescribe the bug
Now, i use wasm-pack for build WASM file and WASM with JavaScript glue layer like this。
The glue layer code contains below code
if (typeof input === 'undefined') {
165 | input = new URL('color_thief_wasm_bg.wasm', import.meta.url);
166 | }
In Vite, after esbuild optimize third party, import.meta.url
cannot be optimize succeed.
Ref Vite Docs, even if set build.target
to es2020
is still the problem
After preprocess
node_modules/color-thief-wasm-web/color_thief_wasm.js
will be transform to node_modules/.vite/deps/color_thief_wasm.js
which load .wasm
file by import.meta.url
receive incorrect path is node_modules/.vite/deps/xxx.wasm
finally, the correct path is node_modules/color-thief-wasm-web/xxx.wasm
One of the solutions is set optimizeDeps.exclude
to exclude third party module like this
Reproduction
https://stackblitz.com/edit/vite-rkrfzu?file=src%2FApp.vue,vite.config.js
System Info
vite@2.9.9
Used Package Manager
npm
Logs
Failed to construct 'URL': Invalid URL
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top GitHub Comments
An ugly practice is move
wasm package
to current project rather thannode_modules
for get correct path@yyx990803 @patak-dev When you plan to resolve the issue?