Importing the correct Wasi module in node.js

795 views Asked by At

I've been stuck on something for some time now. I'm trying to use WebAssembly from Node.js, but in order to do that, I need NodeJs to instantiate a Wasi object. This is implemented here: https://github.com/nodejs/node/blob/master/lib/wasi.js and the documentation is here: https://nodejs.org/api/wasi.html

It is imported through import { WASI } from 'wasi';

But I have no idea how to access the correct wasi implementation, when I add wasi to the dependencies it will install https://www.npmjs.com/package/wasi which is an old user implementation which I don't need. It also does not conform the API documentation from above, it is not usable. My IDE's (WebStorm) code inspection features act as if it is the correct implementation, but when executing the code, it becomes clear it's using a wrong implementation.

If I don't install any at all package I get Cannot find package 'wasi' imported from ...

So the question is, how do I use the WASI class declared in https://github.com/nodejs/node/blob/master/lib/wasi.js?

1

There are 1 answers

0
JonasAnon On

The solution is to include the command line argument --experimental-wasi-unstable-preview1 when running node! (noted underneath the code example in https://nodejs.org/api/wasi.html)

Ex: node --experimental-wasi-unstable-preview1 index.js