import createPlugin from "@extism/extism";
async function main() {
const plugin = await createPlugin(
{
wasm: [
{ url: "https://github.com/extism/plugins/releases/latest/download/count_vowels.wasm" },
],
},
{
useWasi: true,
runInWorker: true,
}
);
let out = await plugin.call("count_vowels", "Yellow, World!");
console.log(out?.text());
}
void main();
When I try running npx tsx index.ts, it throws an error about invalid worker URL:
Emitted 'error' event on Worker instance at:
at [kOnErrorMessage] (node:internal/worker:326:10)
at [kOnMessage] (node:internal/worker:337:37)
at MessagePort.<anonymous> (node:internal/worker:232:57)
at [nodejs.internal.kHybridDispatch] (node:internal/event_target:814:20)
at exports.emitMessage (node:internal/per_context/messageport:23:28) {
code: 'ERR_INVALID_URL',
input: 'worker.js.map',
base: 'data:text/javascript;base64,dmFyIE....
This error does not occur when running with the Node.js command: node index.js (index.js has the same content as index.ts above).
File: index.ts
When I try running
npx tsx index.ts
, it throws an error about invalid worker URL:This error does not occur when running with the Node.js command: node index.js (index.js has the same content as index.ts above).
I guess the reason might be due to converting the URL to base64 here: https://github.com/extism/js-sdk/blob/b4aba72c01e9e8cf3218266312652d043745f3c1/src/worker-url.ts#L2
Changing from
src/worker-url.ts
tosrc/polyfills/bun-worker-url.ts
accidentally makenpx tsx index.ts
run well!I'm not sure about the root cause. Based on my research, using ts-import from tsx might help: https://tsx.is/dev-api/ts-import