Undici error (Drizzle + Next.js 13.5)

I'm getting an odd error with Undici; after looking things up, I've not had any luck. Here is the error I'm getting:
⨯ Internal error: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
⨯ Internal error: TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
The only place in which I use Undici is here:
import { migrate } from "drizzle-orm/planetscale-serverless/migrator";
import { connect } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

import { fetch } from "undici";

import "dotenv/config";

const runMigrate = async () => {
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined");
}

const connection = connect({
url: process.env.DATABASE_URL!,
fetch: fetch,
});

const db = drizzle(connection);

console.log("⏳ Running migrations...");

const start = Date.now();

await migrate(db, { migrationsFolder: "src/lib/db/migrations" });

const end = Date.now();

console.log(`✅ Migrations completed in ${end - start}ms`);

process.exit(0);
};

runMigrate().catch((err) => {
console.error("❌ Migration failed");
console.error(err);
process.exit(1);
});
import { migrate } from "drizzle-orm/planetscale-serverless/migrator";
import { connect } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

import { fetch } from "undici";

import "dotenv/config";

const runMigrate = async () => {
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not defined");
}

const connection = connect({
url: process.env.DATABASE_URL!,
fetch: fetch,
});

const db = drizzle(connection);

console.log("⏳ Running migrations...");

const start = Date.now();

await migrate(db, { migrationsFolder: "src/lib/db/migrations" });

const end = Date.now();

console.log(`✅ Migrations completed in ${end - start}ms`);

process.exit(0);
};

runMigrate().catch((err) => {
console.error("❌ Migration failed");
console.error(err);
process.exit(1);
});
Even after removing this, I get the same error. Does anyone have any idea what this could be associated with? Also, the odd thing is… I’m not running this at all. It happens when I try to insert a new record into the database. For reference, I am using Drizzle inside of my server actions.
3 Replies
Paul
Paul14mo ago
Without reading into any documentation, I don’t think you need the fetch variable when connecting? If you do, try using the native fetch and see if it works to break down what the issue might be
rcssdy
rcssdyOP14mo ago
That's what I thought, even after removing this, and mention of undici in my repository, the error still occurs.
rcssdy
rcssdyOP14mo ago
https://github.com/vercel/next.js/issues/54961 - Appears to be a known issue.
GitHub
next js 13 server error " TypeError: fetch failed " · Issue #54961 ...
Link to the code that reproduces this issue or a replay of the bug https://github.com/AhmedShehata98/shoperz To Reproduce Start the application with npm run dev After many re-render or refresh Faci...
Want results from more Discord servers?
Add your server