All guidesMore providers: databases, auth, hosting, email and payments
On this page

PlanetScale error

PlanetScale "TypeError: fetch failed" with getaddrinfo ENOTFOUND undefined on Vercel

By Ohad Krispin, founder of VibeRaven · LinkedIn

Short answer

"TypeError: fetch failed" with the cause "getaddrinfo ENOTFOUND undefined" means the PlanetScale serverless driver (@planetscale/database) tried to reach a host named undefined, because no connection value reached connect(). With connect({ url: process.env.DATABASE_URL }), an unset or empty DATABASE_URL leaves the host empty, and the driver builds the address https://undefined. It usually works locally because the value sits in a local .env file that is not deployed. Add DATABASE_URL in Vercel for Production and Preview and redeploy, because Vercel applies changed variables only to new deployments. A value wrapped in quotes fails differently, with TypeError: Invalid URL. Reproduced with @planetscale/database 2.0.0 on 2026-10-31.

Before you launch: run

npx -y viberaven@1.8.0 check
.

It lists launch gaps in a Vercel + Supabase repo, such as tables without row level security in the migrations and a service role key in client code. It runs locally with no account and reads the repo, not your live database: advice, not a gate.

Or ask your coding agent to "run npx -y viberaven@1.8.0 check and fix what it reports".

What does the full error look like?

The driver sends its queries with the global fetch function, which in Node is built on undici. When fetch cannot connect, it throws a TypeError whose message is only "fetch failed"; the reason is in error.cause. The driver's maintainers say in database-js issue 142 that this comes from the runtime's networking libraries, so log the cause before you guess.

Output
try {
  await conn.execute("select 1");
} catch (err) {
  console.error(err.message, err.cause);
}

fetch failed
Error: getaddrinfo ENOTFOUND undefined {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'undefined'
}

Which bad DATABASE_URL values give which error?

In @planetscale/database (src/index.ts), the connection reads config.url only when it is a non-empty string; otherwise it builds https:// plus config.host. Both paths end at the host undefined when the variable is missing. In a run of version 2.0.0 on 2026-10-31 with made-up values, nothing reached a PlanetScale host:

The same ENOTFOUND shows up with a quoted host in database-js issue 111, where "aws.connect.psdb.cloud" kept its quotes after a Fly.io secrets import. The fix there was to store the value without quotes.

Output
url: undefined                   TypeError: fetch failed  (ENOTFOUND undefined)
url: ""                          TypeError: fetch failed  (ENOTFOUND undefined)
url: "'mysql://u:p@host/db'"      TypeError: Invalid URL
url: "u:p@host/db"               TypeError: Invalid URL
host: undefined (host config)    TypeError: fetch failed  (ENOTFOUND undefined)

How do I make the error name the missing variable?

Check the value before you call connect(), so the log says which variable is missing instead of fetch failed. The driver uses HTTP because, as PlanetScale's serverless driver tutorial explains, some serverless and edge hosts block arbitrary outbound TCP connections.

Code
import { connect } from "@planetscale/database";

const url = process.env.DATABASE_URL;
if (!url) throw new Error("DATABASE_URL is not set");

export const conn = connect({ url });

How to fix it, then check the fix

  1. 1
    Find every place the app reads the connection value, including the host, username and password form of the config:
    Terminal
    grep -rnE "DATABASE_URL|DATABASE_HOST|@planetscale/database" --include=*.ts --include=*.tsx --include=*.js --exclude-dir=node_modules --exclude-dir=.next .
  2. 2
    Add the variable in Vercel for each environment that runs the code:
    Terminal
    vercel env add DATABASE_URL production
    vercel env add DATABASE_URL preview
  3. 3
    Paste the value without quotes around it. A value that keeps its quotes gives Invalid URL, and a host that keeps them gives ENOTFOUND with the quotes in the hostname.
  4. 4
    Add DATABASE_URL= with no value to .env.example, and the guard from the section above to the file that calls connect().
  5. 5
    Redeploy, because Vercel applies changed variables only to new deployments. Then open a route that runs a query. It should return rows instead of fetch failed.

Official docs behind this checklist

FAQ for builders before launch

Why does it work locally?

The value is usually in a local .env file. Vercel does not read it. A variable exists on Vercel only when it is set in the project for that environment: Production, Preview or Development.

Does the same fetch failed have other causes?

Yes. database-js issue 111 is a quoted hostname from a secrets import, and issue 142 is a fetch failed whose cause the maintainers tie to SSL or TLS. The cause line tells you which one you have, and undefined in it means a missing value.

Does Prisma with PlanetScale show the same error?

Not this one. Prisma's PlanetScale page uses a connection string with the host aws.connect.psdb.cloud and sslaccept=strict, or the @prisma/adapter-planetscale adapter on top of this driver. A missing DATABASE_URL in Prisma fails earlier, with P1012 "Environment variable not found: DATABASE_URL".