Psa: crate instant needs feature stdweb/wasm-bindgen for wasm32

Normally, I wouldn't post this. This cost me an afternoon + evening of my life; posting this in case it saves someone else time.



  • A struct emulating the behavior of std::time::Instant if you are targeting wasm32-unknown-unknown or wasm32-unknown-asmjs and you enabled either the stdweb or the wasm-bindgen feature. This emulation is based on the javascript function.


If you add instant as a dependency, but fail to add stdweb/wasm-bindgen as a feature, what will happen is:

  1. the code will compile fine

  2. if the code calls instant::Instant::new(), then at runtime, during init() (not main()), it will throw an error of:

Uncaught TypeError: Failed to resolve module specifier "env". Relative references must start with either "/", "./", or "../"

What makes this error fun to debug is that it happens during init(), not main(), which means we can't use printf to binary search / locate the error.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.