Closed v-moravec closed 1 year ago
Sounds like the driver is trying to access SubtleCrypto in a context where it's not available.
?sslmode=require
at the end of your connection string, are you able to take that off (e.g. if connecting to a local DB in development)?crypto.subtle
is defined without needing to import anything)?--experimental-global-webcrypto
flag?crypto
as a global before you dynamically import the driver? That would look something like:import crypto from "crypto";
globalThis.crypto = crypto;
const { Pool } = await import('@neondatabase/serverless');
Well, it seems to be fixed with 0.4.9 (also works in 0.4.4 and lower). However with 0.4.9 I'm getting this now on Cloudflare Pages (using Workers under the hood) - Uncaught TypeError: Pool is not a constructor
, locally it works ok with yarn dev
, but not with building it with wrangler and wrangler pages dev dist/
.
OK, good to hear. I think changes in the underlying pg package, which I'd previously omitted to pin to a specific version, must have been responsible for the earlier issues, then.
I've not encountered this new error before. Are you able to provide a simple repro?
Sure, here it is - https://github.com/v-moravec/drizzle-cf-error, hope it helps. I turned off minification so error messages are clear. Everything else that needs to be setup is in readme.
OK, I think the relevant change in 0.4.4 is that we introduced a default export (we're testing something here that will be launched soon). Anyway, it seems the default import is breaking named imports in this particular context.
I'm not yet sure where the fault lies, if anywhere, because judging by these esbuild issues (https://github.com/evanw/esbuild/issues/1719, https://github.com/evanw/esbuild/issues/532), default import interoperability is a minefield.
So I worry that fixing this may break something else. But anyway, I'm continuing to investigate ...
I've just released 0.4.10, which I believe will fix your import problem. Please do let me know either way.
I can confirm everything works as expected now.
Steps to reproduce
npx nuxi init \<project-name> yarn add drizzle-orm @neondatabase/serverless yarn add -D drizzle-kit
db.ts
Expected result
Should work
Actual result
Instead throws error
Environment
Nuxt 3.5 @neondatabase/serverless 0.4.5 Node v18.12.0
Logs, links
ERROR [worker reload] [worker init] Cannot read properties of undefined (reading 'subtle') 3:07:35 PM
at node_modules/@neondatabase/serverless/index.js:1:59242 at node_modules/@neondatabase/serverless/index.js:1:347 at node_modules/@neondatabase/serverless/index.js:1:60107 at node_modules/@neondatabase/serverless/index.js:1:347 at node_modules/@neondatabase/serverless/index.js:46:2299 at node_modules/@neondatabase/serverless/index.js:1:347 at node_modules/@neondatabase/serverless/index.js:46:25042 at node_modules/@neondatabase/serverless/index.js:1:347 at Object. (node_modules/@neondatabase/serverless/index.js:46:25975)
at Module._compile (node:internal/modules/cjs/loader:1159:14)