`TypeError: at normalizeAndValidateHeaderValue` with data proxy in cloudflare workers/miniflare
See original GitHub issueBug description
Client is bugged in my closed source project but also in this open source project I found it so using that as an example.
When using Prisma Data Proxy in Cloudflare Workers with prisma
3.10.0 and miniflare
2.3.0 (also using remix
1.2.3 but probably not related) an error occurs when making any request since the transactionId
header is passed as undefined in prisma causing a header normalization error (since undefined isn’t a valid header).
Workaround
I’ve managed to fix the error locally by modifying line 93 col 13582 of node_modules/@prisma/client/runtime/proxy.js
to be const headers={...n};if(typeof t=="string"&&r){headers.transactionId= t}return{inTx:typeof t=="number"&&r?!0:void 0,headers}
instead of return{inTx:typeof t=="number"&&r?!0:void 0,headers:{transactionId:typeof t=="string"&&r?t:void 0,...n}
since in the bugged code the transactionId
header will be undefined if not present, thus causing the normalizeAndValidateHeaderValue
error.
How to reproduce
- Go to https://github.com/marcomafessolli/remix-prisma-cloudflare-workers/tree/d86bb949016ce35f805ab113f4df89f3e96b3644 (hard link for current point in time of master branch)
- Git clone that project
- Follow the steps to run the project (add an .env,
npm i
,PRISMA_CLIENT_ENGINE_TYPE=dataproxy npx prisma generate
and create your prisma data proxy project if not already using one) - Run
npm run dev
- Open the root index page for the website (only one page exists).
- See error
Expected behavior
TypeError:
[dev:*worker] at normalizeAndValidateHeaderValue (`<PATH>/remix-prisma-cloudflare-workers/node_modules/undici/lib/fetch/headers.js:42:11`)
[dev:*worker] at HeadersList.append (`<PATH>/remix-prisma-cloudflare-workers/node_modules/undici/lib/fetch/headers.js:98:29`)
[dev:*worker] at fill (`<PATH>/remix-prisma-cloudflare-workers/node_modules/undici/lib/fetch/headers.js:86:15`)
[dev:*worker] at new Request (`<PATH>/remix-prisma-cloudflare-workers/node_modules/undici/lib/fetch/request.js:433:9`)
[dev:*worker] at new Request (`<PATH>/remix-prisma-cloudflare-workers/node_modules/@miniflare/core/src/standards/http.ts:407:13`)
[dev:*worker] at upgradingFetch (`<PATH>/remix-prisma-cloudflare-workers/node_modules/@miniflare/web-sockets/src/fetch.ts:20:19`)
[dev:*worker] at WebSocketPlugin.<anonymous> (`<PATH>/remix-prisma-cloudflare-workers/node_modules/@miniflare/core/src/standards/http.ts:895:21`)
[dev:*worker] at fetch (`<PATH>/remix-prisma-cloudflare-workers/node_modules/@miniflare/web-sockets/src/plugin.ts:51:28`)
[dev:*worker] at request (`<PATH>/remix-prisma-cloudflare-workers/node_modules/@prisma/client/runtime/proxy.js:25:12296`)
[dev:*worker] at Object.requestInternal (`<PATH>/remix-prisma-cloudflare-workers/node_modules/@prisma/client/runtime/proxy.js:27:285`)
Prisma information
generator client {
provider = "prisma-client-js"
previewFeatures = ["mongoDb", "dataProxy"]
}
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String?
}
model Log {
id String @id @default(auto()) @map("_id") @db.ObjectId
level Level
message String
meta Json
}
enum Level {
Info
Warn
Error
}
Environment & setup
OS: Windows using Fedora 35 via wsl2 Database: PostgreSQL Miniflare: 2.3.0 Prisma: 3.10.0
Prisma Version
3.10.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:17 (3 by maintainers)
Top GitHub Comments
Hey everyone, hey @kettanaito 👋. We have released this fix a few minutes ago in 3.15.0. I can confirm that I could get the reproduction working again, and the warnings around
eval
are also gone. tl;dr;PRISMA_CLIENT_ENGINE_TYPE
, useprisma generate --data-proxy
to enable the Data Proxyimport { PrismaClient } from '@prisma/client/edge'
for a Workers-compatible Prisma Client.env
aren’t bundled into the generated Prisma Client any longer (see docs)Thanks everyone, and your feedback is welcome.
You should be able to fully remove this alias and just replace your
@prisma/client
import with@prisma/client/edge
.