Describe 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
Used Package Manager
npm
Logs
Failed to construct 'URL': Invalid URL
Validations
Describe 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
In Vite, after esbuild optimize third party,
import.meta.urlcannot be optimize succeed.Ref Vite Docs, even if set
build.targettoes2020is still the problemAfter preprocess
node_modules/color-thief-wasm-web/color_thief_wasm.jswill be transform tonode_modules/.vite/deps/color_thief_wasm.jswhich load.wasmfile byimport.meta.urlreceive incorrect path isnode_modules/.vite/deps/xxx.wasmfinally, the correct path isnode_modules/color-thief-wasm-web/xxx.wasmOne of the solutions is set
optimizeDeps.excludeto exclude third party module like thisReproduction
https://stackblitz.com/edit/vite-rkrfzu?file=src%2FApp.vue,vite.config.js
System Info
Used Package Manager
npm
Logs
Failed to construct 'URL': Invalid URLValidations