-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
import.meta.url not available in dependencies, wasm-pack modules unusable in dev mode? #7287
Comments
I believe this is a bug of vite, it trys to transform the esm dep to esm 2019 using esbuild: vite/packages/vite/src/node/build.ts Lines 276 to 281 in c2ab324
esbuild will convert |
Is this the same as #5270? |
@bluwy Yes, I confirm that set |
@bluwy esbuild will report an warning when build to target that does not support I think we should log this warning to user, or change this warning to our own warning to guide user to change their |
I think a warning is good for the interim, but I haven't took a deeper look of why this happens in the first place and whether it can be fixed within esbuild (or Vite), so we can fix it without any warnings in the first place. Feel free to hack a PR out if you want though, it makes sense to me that I'll close this issue then in favour of #5270 so we can keep the discussion in one place. Thanks for looking into this! |
Thanks all!
Yes, this fixes the URL error. It introduces a new one however ( |
So apparently the package is 'optimized' and put in import { defineConfig } from "vite";
export default defineConfig({
optimizeDeps: {
exclude: ["@webonnx/wonnx-wasm"],
esbuildOptions: {
target: "es2020",
},
},
}); |
Describe the bug
I have built a package (@webonnx/wonnx-wasm) containing a WebAssembly module from Rust using wasm-pack. The source is here, command line used to build:
RUSTFLAGS=--cfg=web_sys_unstable_apis wasm-pack build --target web -d `pwd`/target/pkg --out-name wonnx --scope webonnx ./wonnx-wasm
I tried building a very simple app using Vite to test the package. Upon opening the app however, I get the following error:
The issue appears to be with this line in the part of the wonnx-wasm package that loads the WebAssembly module:
Further digging revealed that
import.meta.url
is undefined here. It is defined when I try to log it from the app code. (So: Vite is likely not defining it for dependencies?).Interestingly running
npm run build
makes it work just fine! (You will likely still see the errorTypeError: Cannot read properties of undefined (reading 'requestAdapter')
in your browser because the package attempts to use WebGPU, that's obviously not a problem in Vite). In the bundle the offending line compiles to:So my question is (1) is this behaving as expected, and (2) if so, how am I supposed to be using packages like this in dev mode (e.g. from wasm-pack) with Vite / is there anything wasm-pack should change?
Reproduction
https://github.com/pixelspark/wonnx-wasm-test
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: