napi-rs / node-rs

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

`wasm32` is not valid cpu value #792

Closed smorimoto closed 8 months ago

smorimoto commented 8 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 8 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 8 months ago

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

smorimoto commented 8 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 8 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 8 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 8 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 8 months ago

That pointer definitely helped me! Thank you!

adumesny commented 3 days ago

I would to add that cpu=wasm32 and forcing user to install this makes no sense to me. while it's easy to yarn install --ignore-platform for this module, it makes yarn to install on build machines and other other devs fail because that yarn.lock file entry doesn't match your machine going forward...

maybe my problem is that even though we targerting browsers, esbuild is for some reason picking this package which traditionally only had .node binary that wouldn't work for browsers anyway and this lib really should not be used, but picked up anyway by esbuild...