0

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/secp256k1@1.7.1/index.ts:6:29

how can I fix this? thanks.

Uri
  • 25,622
  • 10
  • 45
  • 72

1 Answers1

2

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/std@0.177.0/node/crypto.ts.

Your import map should look something like:

{
  "imports": {
    "crypto": "https://deno.land/std@0.177.0/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

IndevSmiles
  • 737
  • 6
  • 17
  • thanks! I knew it was something simple. I will just add to other readers that this needs to be in `deno.json` in the root of working directory. – Uri Mar 14 '23 at 15:30