smol-rs / fastrand

A simple and fast random number generator
Apache License 2.0
409 stars 35 forks source link

wasm: Uncaught TypeError: Error resolving module specifier “env” #34

Closed schell closed 2 years ago

schell commented 2 years ago

I've run into an interesting bug where attempting to run a wasm32-compiled program with fastrand in it gives this error in the console:

Uncaught TypeError: Error resolving module specifier “env”. Relative module specifiers must start with “./”, “../” or “/”.

I'm using fastrand = "1.8.0"

I encountered this after adding futures-lite to my project, which depends on fastrand. https://github.com/rustwasm/wasm-bindgen/issues/2215 explains a few reasons why this error might pop up.

I got around this problem by using futures_lite::StreamExt::or instead of futures_lite::StreamExt::race. race uses fastrand::bool, whereas or does not.

taiki-e commented 2 years ago

Duplicate of #27

notgull commented 2 years ago

Note that if you compile and run the program in a WASI environment, it should all work out.