hattipjs / hattip

Like Express, but for the future

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot set propery crypto of Object with Node.js 19

QuiiBz opened this issue · comments

When using the todo template from Rakkas and accessing the dev server, the following error is thrown:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

TypeError: Cannot set property crypto of #<Object> which has only a getter
    at Module.install (/node_modules/.pnpm/@hattip+polyfills@0.0.20/node_modules/@hattip/polyfills/dist/crypto.js:7:21)
    at eval (/node_modules/.pnpm/@hattip+adapter-node@0.0.20/node_modules/@hattip/adapter-node/dist/index.js:15:30)
    at async instantiateModule (file:///home/parallels/rakkas/node_modules/.pnpm/vite@3.2.2/node_modules/vite/dist/node/chunks/dep-c842e491.js:54236:9)

From my tests, this error only appears with Node.js >= 19. Running the same test with the LTS (18.12.1 as of writing) works properly. It makes sense since Node.js 19 added native support for globalThis.crypto (https://nodejs.org/en/blog/announcements/v19-release-announce/#stable-webcrypto)

Node: 19.0.1
PNPM: 7.14.0
OS: Ubuntu 20.04

Node.js 19 added native support for globalThis.crypto

That's good news actually :)

We're only testing against Node 14/16/18, that's why it wasn't caught earlier. I'll fix it as soon as I can.

Thanks for reporting!

Solved in 0.0.21 but your case requires a Rakkas update too, which I don't have the time for yet. (Otherwise you'll get type errors, HatTip packages are moving in lockstep versions until the API stabilizes a little, but pnpm overrides or ignoring the errors might be a workaround for now).

Rakkas updated with 0.0.22 which solves the problem for me.