Cheat sheet not working
terrablue opened this issue · 4 comments
Hi, when following the steps at https://github.com/ruby/ruby.wasm/blob/main/docs/cheat_sheet.md#nodejs, I get the following error:
import { DefaultRubyVM } from "@ruby/wasm-wasi/dist/node";
^^^^^^^^^^^^^
SyntaxError: Named export 'DefaultRubyVM' not found. The requested module '@ruby/wasm-wasi/dist/node' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@ruby/wasm-wasi/dist/node';
const { DefaultRubyVM } = pkg;
If I copy node_modules/@ruby/3.2-wasm-wasi/dist/node.esm.js locally and import it relatively, I don't get that error. However, I then get another error:
node:wasi:51
validateString(options.version, 'options.version');
^
TypeError [ERR_INVALID_ARG_TYPE]: The "options.version" property must be of type string. Received undefined
at new WASI (node:wasi:51:5)
at DefaultRubyVM (file:///home/blue/projects/primate-ffi/ruby/node.esm.js:1193:18)
at file:///home/blue/projects/primate-ffi/ruby/index.js:7:22 {
code: 'ERR_INVALID_ARG_TYPE'
}
I fixed this by changing the WASI instantiation code at line 1193 to
const wasi = new WASI({ env: options.env, version: 'preview1' });
Using Node v21.4.0.
Thank you for your report :) The first one, ESM import issue, will be fixed in the next 2.4.0 release. The sample code was recently written targeting the next release.
The second issue is related to #314, but we can just add the field in browser.ts now.
Thanks.
The second issue is related to #314, but we can just add the field in browser.ts now.
Alright cool, so the solution would be to vendor node.esm.js until that is fixed?
Alright cool, so the solution would be to vendor node.esm.js until that is fixed?
Yes, that would be a temporal solution until we release the next patch release. Or you can use tomorrow's nightly release.
Thanks!