diff --git a/esm/package.json b/esm/package.json index cf1903a..cfdc1a5 100644 --- a/esm/package.json +++ b/esm/package.json @@ -4,6 +4,7 @@ "node:crypto": false }, "node": { + "./crypto.js": "./esm/cryptoNode.js", "./crypto": "./esm/cryptoNode.js" } } diff --git a/src/package.json b/src/package.json new file mode 100644 index 0000000..3dbc1ca --- /dev/null +++ b/src/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/webcrypto.ts b/src/webcrypto.ts index d8bd40c..21005d2 100644 --- a/src/webcrypto.ts +++ b/src/webcrypto.ts @@ -4,6 +4,9 @@ // from `crypto` to `cryptoNode`, which imports native module. // Makes the utils un-importable in browsers without a bundler. // Once node.js 18 is deprecated, we can just drop the import. +// +// Use full path so that Node.js can rewrite it to `cryptoNode.js`. +// @ts-ignore: `tsc` doesn't understand `@noble/ciphers/crypto` is a valid import. import { randomBytes, getWebcryptoSubtle } from '@noble/ciphers/crypto'; import { Cipher, concatBytes } from './utils.js'; import { number } from './_assert.js'; diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 7726d8b..a5b771e 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -16,9 +16,9 @@ "paths": { "@noble/ciphers/crypto": ["src/crypto"] }, - "module": "es2020", + "module": "Node16", "outDir": "esm", - "moduleResolution": "bundler" + "moduleResolution": "Node16" }, "include": ["src"], "exclude": ["node_modules", "lib"]