Sabah Kaldwin
Sabah Kaldwin15mo ago

How to import a npm package that relies on Wasm

I'm trying to import npm:@biscuit-auth/biscuit-wasm@0.4.0 and I wrote the following script:
import * as biscuitAuth from "npm:@biscuit-auth/biscuit-wasm@0.4.0";

const root = new biscuitAuth.KeyPair();
console.log(root);
import * as biscuitAuth from "npm:@biscuit-auth/biscuit-wasm@0.4.0";

const root = new biscuitAuth.KeyPair();
console.log(root);
However, I get the following error:
error: Unable to load ~/.cache/deno/npm/registry.npmjs.org/@biscuit-auth/biscuit-wasm/0.4.0/module/biscuit_bg.wasm imported from ~/.cache/deno/npm/registry.npmjs.org/@biscuit-auth/biscuit-wasm/0.4.0/module/biscuit.js

Caused by:
stream did not contain valid UTF-8
error: Unable to load ~/.cache/deno/npm/registry.npmjs.org/@biscuit-auth/biscuit-wasm/0.4.0/module/biscuit_bg.wasm imported from ~/.cache/deno/npm/registry.npmjs.org/@biscuit-auth/biscuit-wasm/0.4.0/module/biscuit.js

Caused by:
stream did not contain valid UTF-8
Looking at this stackoverflow post https://stackoverflow.com/questions/43122335/what-does-stream-did-not-contain-valid-utf-8-mean tells me that this error message comes from rust directly. Separately, I also tried out the following in node js:
import { KeyPair } from '@biscuit-auth/biscuit-wasm';

const root = new KeyPair();

console.log(root);
import { KeyPair } from '@biscuit-auth/biscuit-wasm';

const root = new KeyPair();

console.log(root);
and ran it with
node --experimental-wasm-modules run.js
node --experimental-wasm-modules run.js
and it ran fine with no issues:
(node:11768) ExperimentalWarning: Importing WebAssembly modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
biscuit-wasm loading
KeyPair { ptr: 1539832 }
(node:11768) ExperimentalWarning: Importing WebAssembly modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
biscuit-wasm loading
KeyPair { ptr: 1539832 }
Could this be part of the solution? Does deno have a --experimental-wasm-modules or something similar that I need to use, or is this an issue with how Deno imports wasm packages from npm?
Stack Overflow
What does "Stream did not contain valid UTF-8" mean?
I'm creating a simple HTTP server. I need to read the requested image and send it to browser. I'm using this code: fn read_file(mut file_name: String) -> String { file_name = file_name.rep...
0 Replies
No replies yetBe the first to reply to this messageJoin