workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

Uncaught Error: LinkError: WebAssembly.Instance(): Import #32 module="env" function="now" error: function import requires a callable

Open B4TT3RY opened this issue 4 years ago • 6 comments

A crates based on html5ever (guessing) doesn't work. Is it possible to solve it?

B4TT3RY avatar Oct 14 '21 11:10 B4TT3RY

Hi @B4TT3RY -

Can you see within html5ever if there is a call to a now function? This is not a function we provide from the WebAssembly host to the imports of the modules.

Also, it would help to debug this if you could upload your wasm binary to this analyzer: https://wasm-analyzer.nilslice.workers.dev/ (you can find your binary after running wrangler build in your project directory under the following path: build/worker/index_bg.wasm

This will produce a list of functions and their arguments & return values based on the imports & exports of the module. Here is an example: https://wasm-analyzer.nilslice.workers.dev/web/7c3a3d4c310ec6237288c0954be50acb1406d2524c1f784ab297e143298f899a

Doing so will create a link, which you can share here. Thank you!

nilslice avatar Oct 15 '21 15:10 nilslice

Hi @B4TT3RY -

Can you see within html5ever if there is a call to a now function? This is not a function we provide from the WebAssembly host to the imports of the modules.

Also, it would help to debug this if you could upload your wasm binary to this analyzer: https://wasm-analyzer.nilslice.workers.dev/ (you can find your binary after running wrangler build in your project directory under the following path: build/worker/index_bg.wasm

This will produce a list of functions and their arguments & return values based on the imports & exports of the module. Here is an example: https://wasm-analyzer.nilslice.workers.dev/web/7c3a3d4c310ec6237288c0954be50acb1406d2524c1f784ab297e143298f899a

Doing so will create a link, which you can share here. Thank you!

Here is link: https://wasm-analyzer.nilslice.workers.dev/web/84a78ce9e98414fc0aedbca93e63e344c0dcb7bafb00a72a8c81324c2870ca2b

I used nipper crate

I wrote this code let document = Document::from(&response_body);

And I couldn't find fn now(i32, i32) -> i32 .

B4TT3RY avatar Oct 17 '21 10:10 B4TT3RY

@nilslice I changed env: { now: Date.now, memory: _wasm_memory } in export_wasm.mjs, it works normally.

I don't know why the now function came out, but I think it may be a problem in the build process.

B4TT3RY avatar Oct 17 '21 11:10 B4TT3RY

Thanks for the info! That function was never there in the build process, and although I'm not positive, I don't think Date.now is the correct function to pass it. It does satisfy the validation, but only by resolving the name of the function.

I have a note to take a look through the nipper crate and its dependencies to see if there is some external function now it expects.

One of the reasons I don't think it's the right now is that the analyzer shows it takes 2 args vs Date.now takes 0. Maybe that isn't correct though so I'll dig a bit deeper here ASAP.

nilslice avatar Oct 17 '21 13:10 nilslice

I have the same issue, though my now takes 4 arguments https://wasm-analyzer.nilslice.workers.dev/web/e15f11bae45a6b49ad874783de1e1f6fb442309f34d64f2d431bce19b543092e

I haven't worked out which package caused this to start happening but I'll try to figure that out

jonohill avatar Mar 20 '22 04:03 jonohill

Culprit package is wasm-timer. My usage is calling Delay::new(delay).await?;

jonohill avatar Mar 20 '22 05:03 jonohill