esm.sh
esm.sh copied to clipboard
Failed to import - js-sha256
Failing module
- GitHub: https://github.com/emn178/js-sha256
- npm: [email protected]
import { sha256 } from "https://esm.sh/[email protected]?dev&no-check&target=deno"
Error message
After running deno run I got this:
error: Uncaught ReferenceError: require is not defined
var crypto = eval("require('crypto')");
^
at eval (eval at nodeWrap (https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:152:22), <anonymous>:1:1)
at nodeWrap (https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:152:22)
at createMethod (https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:137:21)
at https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:516:21
at esm-build-82b454cebf87682b90e9c5a3fa3db93fdb261443-e0f5f3a5/node_modules/js-sha256/src/sha256.js (https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:532:7)
at __require (https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:13:50)
at https://cdn.esm.sh/v64/[email protected]/deno/js-sha256.development.js:537:32
Additional info
- esm.sh version: v64
- Deno version: 1.18.0
This was previously working on v57, but even with a pin it is now breaking on my local build. This is a sub-dependency of @project-serum/anchor.
I've also identified the issue to be with this line: https://github.com/emn178/js-sha256/blob/master/src/sha256.js#L83
var crypto = eval("require('crypto')");
Because the require is contained within an eval it is unable to be rewritten by esm.sh. I also tried globally setting window.JS_SHA256_NO_NODE_JS but it was not evaluated properly before the code was executed.
why not use deno std/hash module? ems.sh can't handle the eval case
why not use deno std/hash module? ems.sh can't handle the
evalcase
This is an internal dependency to @project-serum/anchor as I mentioned in the issue above. It allows you to override this behavior with global variables on window but it doesn't seem to work when I try it from my entry point in Deno.
there is a workaround maybe work:
import crypto from "https://esm.sh/crypto"
globalThis.require = (name) => {
if (name == "crypto") return crypto
}
import "@project-serum/anchor"