using paulmillr/noble-secp256k1 with deno deploy

328 Views Asked by At

I have this line in my file: import * as secp256k1 from "npm:@noble/secp256k1";

It works fine locally (deno run)

When I try to deno deploy, it cannot find the module.

I read this is because deno deploy doesn't yet support npm:.

To circumvent it I tried using import * as secp256k1 from "https://deno.land/x/secp256k1/mod.ts", but this doesn't work locally. I'm getting

error: Relative import path "crypto" not prefixed with / or ./ or ../
If you want to use a built-in Node module, add a "node:" prefix (ex. "node:crypto").
    at https://deno.land/x/[email protected]/index.ts:6:29

how can I fix this? thanks.

1

There are 1 best solutions below

1
On BEST ANSWER

The documentation for /x/secp256k1 says:

To use the module with Deno, you will need import map

In this case, you will need to polyfill node's crypto. In the future this will be done using node:crypto, but for now deploy does not support this and you must use https://deno.land/[email protected]/node/crypto.ts.

Your import map should look something like:

{
  "imports": {
    "crypto": "https://deno.land/[email protected]/node/crypto.ts"
  }
}

Here is an example of using import maps with deploy (it's just how you would expect): https://github.com/satyarohith/import_map