wasmerio / wasmer-js

Monorepo for Javascript WebAssembly packages by Wasmer

Home Page:https://wasmerio.github.io/wasmer-js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use the registry for the JS-SDK?

may-20i opened this issue · comments

import { init, Wasmer } from "@wasmer/sdk";

const main = async () => { 
    await init();
    
    const pkg = await Wasmer.fromRegistry("python/python@3.12");

    if (!pkg || !pkg.entrypoint) {
        throw new Error("Could not find package");
    }

    const instance = await pkg.entrypoint.run({
        args: ["-c", "print('Hello, World!')"],
    });
    
    const { code, stdout } = await instance.wait();
    console.log(`Python exited with ${code}: ${stdout}`);
}

main().catch(console.error);
Error: Unable to find "python/python@^3.12" in the registry
    at V.e.wbg.__wbg_new_ab87fd305ed9004b (/Users/May/Documents/Projects/wasmer/npm/node_modules/@wasmer/sdk/dist/WasmerSDK.cjs:11:21341)
    at null.<anonymous> (https://unpkg.com/@wasmer/sdk@0.6.0/dist/wasmer_js_bg.wasm:1:2926914)
    at null.<anonymous> (https://unpkg.com/@wasmer/sdk@0.6.0/dist/wasmer_js_bg.wasm:1:3805685)
    at null.<anonymous> (https://unpkg.com/@wasmer/sdk@0.6.0/dist/wasmer_js_bg.wasm:1:1228216)
    at null.<anonymous> (https://unpkg.com/@wasmer/sdk@0.6.0/dist/wasmer_js_bg.wasm:1:3280471)
    at null.<anonymous> (https://unpkg.com/@wasmer/sdk@0.6.0/dist/wasmer_js_bg.wasm:1:4137502)
    at null.<anonymous> (https://unpkg.com/@wasmer/sdk@0.6.0/dist/wasmer_js_bg.wasm:1:4107522)
    at x (/Users/May/Documents/Projects/wasmer/npm/node_modules/@wasmer/sdk/dist/WasmerSDK.cjs:11:2869)
    at i (/Users/May/Documents/Projects/wasmer/npm/node_modules/@wasmer/sdk/dist/WasmerSDK.cjs:11:2709) {
  detailedMessage: 'Unable to find "python/python@^3.12" in the registry\n' +
    '\n' +
    'Caused by:\n' +
    '    0: oneshot canceled\n' +
    '    1: oneshot canceled',
  causes: [ 'oneshot canceled', 'oneshot canceled' ]
}

Is there something I'm clearly doing wrong? Just trying to follow along with the docs: https://docs.wasmer.io/javascript-sdk

I'm using Node v21.5.0.

@may-20i are you seeing any other errors or warnings in the console?

Usually this happens when we can't start the thread pool because the web page isn't being served from a "secure" context (i.e. HTTPS or localhost with the right headers). If this is the case, you should also see a warning that mentions Cross-Origin Isolation and points to https://docs.wasmer.io/javascript-sdk/explainers/troubleshooting#sharedarraybuffer-and-cross-origin-isolation in the docs.

Can you also describe how you are running this script? At the moment, the Wasmer SDK will only run in the browser due to its use of web APIs. Support for NodeJS is tracked in #387.

This would make sense, my guess is it is throwing that error silently or is expecting some kind of browser specific behavior. I was able to setup the cross-origin shenanigans with Vite for the browser version and it worked great.

(Here is that Vite config for reference.)

export default defineConfig({ 
  server: 
    { 
      headers: { 
        "Cross-Origin-Embedder-Policy": "require-corp",
        "Cross-Origin-Opener-Policy": "same-origin", 
      }, 
    },
});

Thank you for letting me know that Node support is being worked on, I missed that somehow... Cheers. (I'm a huge fan of WASM, thank you for the help c:)

This would make sense, my guess is it is throwing that error silently or is expecting some kind of browser specific behavior.

This might be because you were running it in Node.

If you were running in the browser without Cross-Origin Isolation, you would see an assertion pointing to the docs:

2023-12-22_16-18

(Here is that Vite config for reference.)

Nice! This is almost identical to the config we recommend in the tutorial.

import { defineConfig } from "vite";
 
export default defineConfig({
    server: {
        headers: {
            "Cross-Origin-Opener-Policy": "same-origin",
            "Cross-Origin-Embedder-Policy": "require-corp",
        },
    },
});