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

Cheat sheet not working #336

Closed
terrablue opened this issue Dec 14, 2023 · 4 comments · Fixed by #337
Closed

Cheat sheet not working #336

terrablue opened this issue Dec 14, 2023 · 4 comments · Fixed by #337

Comments

@terrablue
Copy link
Contributor

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.

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Dec 14, 2023

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.

@terrablue
Copy link
Contributor Author

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?

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Dec 14, 2023

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.

@terrablue
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants