cmdruid / tapscript

A humble library for working with Tapscript and Bitcoin Transactions.
https://www.npmjs.com/package/@cmdcode/tapscript
Creative Commons Zero v1.0 Universal
196 stars 50 forks source link

ReferenceError: crypto is not defined #30

Closed ChristianOConnor closed 8 months ago

ChristianOConnor commented 9 months ago

I got this error:

C:\path\to\my\project\node_modules\@cmdcode\tapscript\node_modules\@cmdcode\buff-utils\dist\module.mjs:353
const { getRandomValues } = crypto ?? globalThis.crypto ?? window.crypto;
                            ^
ReferenceError: crypto is not defined
    at Object.<anonymous> (C:\path\node_modules\@cmdcode\tapscript\node_modules\@cmdcode\buff-utils\dist\module.mjs:353:29)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .js] (C:\path\to\AppData\Local\npm-cache\_npx\<random looking num here>\node_modules\ts-node\src\index.ts:1608:43)       
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (C:\path\to\my\project\index.ts:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)

When I try to run my script that looks like this "index.ts.":

const { Address, Signer, Tap, Tx, } = require('@cmdcode/tapscript')

function main() {
    const address = 'address here'
    const decoded = Address.decode(address)
    console.log(decoded)
}

main()
cmdruid commented 9 months ago

Try updating your nodejs version to 19 or above.