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

apollo_compiler encounters runtime error in wasm usages #844

Closed
trevor-scheer opened this issue Mar 24, 2024 · 2 comments
Closed

apollo_compiler encounters runtime error in wasm usages #844

trevor-scheer opened this issue Mar 24, 2024 · 2 comments
Labels
bug Something isn't working triage

Comments

@trevor-scheer
Copy link
Member

Description

I tried using apollo_compiler in a wasm context. My Rust app compiles successfully but encounters a "Module not found" error (seemingly at the wasm-pack step being handled by webpack, though that's not entirely apparent to me).

I mention this in the repro README, but it seems Instant::now is unavailable in wasm and somewhere in the dependency tree of apollo_compiler it's being used. Unfortunately this isn't caught as part of building for wasm, else this error would turn up in our wasm build step in CI.

Also in the README but worth referencing here, this thread is highly relevant.

Steps to reproduce

Clone this repo:
https://github.com/trevor-scheer/compiler-wasm-reproduction
Reproduction steps are at the bottom of the README.

The initial commit comes from this handy template. Things run as expected from that commit. The second commit shows my diff which introduces apollo_compiler usage and the error mentioned in the README occurs.

Expected result

I expect to be able to use apollo_compiler in a wasm context without module resolution errors.

Actual result

Module resolution error:

ERROR in ./pkg/index_bg.wasm
Module not found: Error: Can't resolve 'env' in '/Users/trevorscheer/Desktop/compiler-wasm-reproduction/pkg'
 @ ./pkg/index_bg.wasm
 @ ./pkg/index.js
 @ ./js/index.js

Environment

Happy to provide more specifics if needed, but I don't think this is env specific

  • Operating system and version: MacOS 14.4 / M1
  • Shell (bash/zsh/powershell): zsh
  • apollo-rs crate: apollo_compiler
  • Crate version: 0.11.3
@trevor-scheer trevor-scheer added bug Something isn't working triage labels Mar 24, 2024
@trevor-scheer
Copy link
Member Author

After digging around a bit more, it became apparent to me the issue was in the usage of the instant crate somewhere within our deps, not std::time::Instant.

The instant crate provides a feature for wasm-bindgen which needs to be enabled in Cargo.toml like so:

instant = { version = "0.1.12", features = [ "wasm-bindgen" ] }

I'm not super familiar with the rust/wasm ecosystem, deps, and features of deps yet so this took me awhile to arrive at the solution. Is this something worth documenting in our README, perhaps?

This issue is probably fine to close, but I will leave it up to you folks in case there's a better solution than the one I've arrived at that y'all have in mind.

@goto-bus-stop
Copy link
Member

goto-bus-stop commented Mar 25, 2024

Instant is not in use anymore in the latest 1.0 betas. New code should use the 1.0 betas rather than 0.11.x!

apollo-compiler = "=1.0.0-beta.14"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants