Skip to content

Instantly share code, notes, and snippets.

@DougAnderson444
Created April 28, 2025 12:19
Show Gist options
  • Save DougAnderson444/390ac884b1b227534ab33784ea358ac9 to your computer and use it in GitHub Desktop.
Save DougAnderson444/390ac884b1b227534ab33784ea358ac9 to your computer and use it in GitHub Desktop.
failed to resolve import `env::now`

When parking_lot is used in a wasm context, sometimes we run into an error with the unknwon target

failed to resolve import `env::now`

The solution is here: Amanieu/parking_lot#269 (comment)

While you can lock parking_lot_core to anything below 0.8.1 (uses the InstantDummy) I would not recommend this. Instead I'd recommend to enable the necessary features transitively when using wasm-bindgen. That means for instant to work on wasm32 you have to enable the wasm-bindgen feature and depending on the platform and whether performance.now() is available, you also need to enable inaccurate.

To fix the issue add instant as a dependency to your own crate and enable the features mentioned above:

[features]
# `instant/wasm-bindgen` makes sure it will use `js_sys` for getting the system time
# `instant/inaccurate` uses `Date.now()` instead of `performance.now()`
default = ["instant/wasm-bindgen", "instant/inaccurate"]

[dependencies]
instant = "0.1.12"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment