napi-rs / node-rs

Node.js bindings ❤️ Rust crates
https://node-rs.dev
MIT License
1.03k stars 32 forks source link

`wasm32` is not valid cpu value #792

Closed smorimoto closed 4 months ago

smorimoto commented 4 months ago

cpu in package.json refers to process.arch, but wasm 32 is not a valid value.

https://github.com/napi-rs/node-rs/blob/de1e89bfd55f444090e4d3dc97dc5772ddd89296/packages/bcrypt/npm/wasm32-wasi/package.json#L4-L6

This might cause an error such as the following:

Module not found: Can't resolve '@node-rs/bcrypt-wasm32-wasi'

Ref

Brooooooklyn commented 4 months ago

We decided to adopt this strategy for releasing the wasm package as discussed in the following issue: https://github.com/napi-rs/napi-rs/issues/1794

If you encounter any issues, comments are welcome in the original issue.

Brooooooklyn commented 4 months ago

On StackBlitz, the value of process.arch will be wasm32 btw

smorimoto commented 4 months ago

Vercel's edge runtime seems to resolve the browser, which requires wasm code, but in the current setup it is not installed in typical environments. It might not be ideal, but it might be helpful to get rid of the cpu constraint to work around the weird error with Next.js + edge runtime.

Brooooooklyn commented 4 months ago

@smorimoto For the edge runtime scenario, you can use npm install --cpu=wasm32 to let the package manager pick the right dependency.

smorimoto commented 4 months ago

You can't use it with yarn. And in esbuild, nothing is specified: https://github.com/evanw/esbuild/blob/main/npm/esbuild-wasm/package.json

Brooooooklyn commented 4 months ago

You can't use it with yarn

For yarn1.x, you can use yarn install --ignore-platform to install wasm32 package For yarn2+, you can set the supportedArchitectures.cpu to ["current", "wasm32"] by running yarn config set --json supportedArchitectures.cpu '["current", "wasm32"]'

We added wasm32 to the CPU field because we don't want to increase the installation size for users who don't want to use the wasm package. And for the platforms like StackBlitz, the user won't need to install an additional package manually like esbuild-wasm to make things work.

And sharp chooses the same strategy to publish wasm package: https://github.com/lovell/sharp/blob/main/npm/wasm32/package.json#L40

smorimoto commented 4 months ago

That pointer definitely helped me! Thank you!