Immutable solution version
0.4.5 Error - Cannot read properties of undefined (reading 'subtle')
Complete solution
How to fix '0.4.5 Error - Cannot read properties of undefined (reading 'subtle')' in Neon, straight from the verified resolution in gh:neondatabase/serverless#19. Root cause plus what to change.
What was reported
Issue neondatabase/serverless#19 (closed, 7 comments): ## Steps to reproduce npx nuxi init [project-name] yarn add drizzle-orm @neondatabase/serverless yarn add -D drizzle-kit
db.ts
import {neonConfig, Pool} from '@neondatabase/serverless';
import {drizzle, NeonDatabase} from 'drizzle-orm/neon-serverless';
import * as schema from '~/server/drizzle/schema';
// if we're running locally
if (!process.env.VERCEL_ENV) {
// Set the WebSocket proxy to work with the local instance
neonConfig.wsProxy = (host) => `${host}:5433/v1`
// Disable all authentication and encryption
neonConfig.useSecureWebSocket = false
neonConfi
## The verified resolution
[jawj (maintainer)]: The driver needs SubtleCrypto. Options: drop `?sslmode=require` when connecting to a local DB in dev; use Node 20 (global webcrypto); Node 18 with `--experimental-global-webcrypto`; or polyfill before import: `import crypto from 'crypto'; globalThis.crypto = crypto;` then dynamically import the driver. Follow-up issue on the same thread - 0.4.4's new default export broke named imports under esbuild/Cloudflare - fixed in 0.4.10 (reporter confirmed).Evidence
Asked in gh:neondatabase/serverless#19 (https://github.com/neondatabase/serverless/issues/19): 0.4.5 Error - Cannot read properties of undefined (reading 'subtle'). The issue report: Issue neondatabase/serverless#19 (closed, 7 comments): ## Steps to reproduce npx nuxi init [project-name] yarn add drizzle-orm @neondatabase/serverless yarn add -D drizzle-kit
db.ts
import {neonConfig, Pool} from '@neondatabase/serverless';
import {drizzle, NeonDatabase} from 'drizzle-orm/neon-serverless';
import * as schema from '~/server/drizzle/schema';
// if we're running locally
if (!process.env.VERCEL_ENV) {
// Set the WebSocket proxy to work with the local instance
neonConfig.wsProxy = (host) => `${host}:5433/v1`
// Disable all authentication and encryption
neonConfig.useSecureWebSocket = false
neonConfi The verified answer: [jawj (maintainer)]: The driver needs SubtleCrypto. Options: drop `?sslmode=require` when connecting to a local DB in dev; use Node 20 (global webcrypto); Node 18 with `--experimental-global-webcrypto`; or polyfill before import: `import crypto from 'crypto'; globalThis.crypto = crypto;` then dynamically import the driver. Follow-up issue on the same thread - 0.4.4's new default export broke named imports under esbuild/Cloudflare - fixed in 0.4.10 (reporter confirmed).By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_FZJTcN5EktLEIWynQYxndQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">0.4.5 Error - Cannot read properties of undefined (reading 'subtle') <span>— Vectle</span></a>