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

Import #0 "wasi_snapshot_preview1": module is not an object or function #499

Open
inhahe opened this issue Nov 18, 2024 · 3 comments
Open

Comments

@inhahe
Copy link

inhahe commented Nov 18, 2024

I have a WASI C++ program that when I compile it and try to import it in my html, I get Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 "wasi_snapshot_preview1": module is not an object or function

What could be causing this?

I added -Oz to the clang command line and that fixed it temporarily, but then when I tried to -Wl,--export=mainloop, I got the error back again. Then I narrowed down one specific part of my C++ code that causes the error, but nothing in that section seemed special or out of the ordinary. It did use some variables that were defined with uint32_t and uint8_t, so I tried redefining them as ints, but I still got the error. Then I kept getting the error even when commenting out the stuff that commenting out made the error go away to begin with!

@sbc100
Copy link
Member

sbc100 commented Nov 18, 2024

The WASI APIs that are part of wasi_snapshot_preview1 are not part of the web platform, so if you want to run a WASI program on the web you would need to use something like https://github.com/bytecodealliance/jco or emscripten.

@inhahe
Copy link
Author

inhahe commented Nov 18, 2024

The WASI APIs that are part of wasi_snapshot_preview1 are not part of the web platform, so if you want to run a WASI program on the web you would need to use something like https://github.com/bytecodealliance/jco or emscripten.

Hmm, I'm not sure what you mean by WASI APIs - WASI functions that you can call in your program? Because I only use normal C++ library functions as far as I can tell. Is there a way to find out what function is trying to load wasi_snapshot_preview1 so that I can eliminate it? Thanks

I have another WASI program that somebody else wrote that's a lot simpler and doesn't give me this error on the web, so I know it's not absolutely necessary to use something like jco or Emscripten.

@sbc100
Copy link
Member

sbc100 commented Nov 18, 2024

Pretty much any WASI program (i.e. any program build with wasi-sdk) will depend on one or more WASI APIs. In theory could could try to build a pure compute module that doesn't call any inports, but there are not very many useful programs in that category and wasi-sdk doesn't have any mechanism to enforce such a thing.. Most WASI program depends on WASI imports, by design.

If you want to find out why a given import is needed you can disassembly the module using wasm-dis (from binaryen) or wasm2wat (from wabt) and then look for wasi_snapshot_preview1 to see which functions are being imported.. you can then search for those function by name to see where there are using in your program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants