drizzle-team / drizzle-team/drizzle-orm

[BUG]:Best Practices for Using drizzle-orm with MySQL on Vercel Next.js Edge Runtime (Minimal Example Requested)

Open
#4,142 4 comments 2 reactions 0 assignees View on GitHub
bug db/mysql
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.39.3

### What version of `drizzle-kit` are you using?

0.30.4

### Other packages

"mysql2": "^3.12.0",

### Describe the Bug

**Issue Description:**

Hello,

I'm currently trying to integrate `drizzle-orm` with a MySQL database in my Next.js project hosted on Vercel. However, when I attempt to use drizzle-orm in an Edge Runtime environment, I run into issues because the Edge Runtime does not support certain Node.js modules (e.g., the `stream` module).

Specifically, after integrating drizzle-orm, my Edge Middleware (or Edge API Routes) fails with an error related to unsupported Node.js APIs. Given these constraints, I have a few questions:

1. **Recommended Usage:**
Is drizzle-orm supported in Edge environments? If so, what is the best practice for using drizzle-orm with MySQL on the Edge Runtime? Should I isolate the database logic in Node.js server functions rather than the Edge Middleware?

2. **Minimal Working Example:**
Could you provide a minimal working example or guidelines that demonstrate how to set up drizzle-orm with MySQL for a project running in the Vercel Next.js Edge environment? This would help in understanding the best way to structure the code and possibly apply the necessary polyfills or workarounds.

Any help or examples you could provide would be greatly appreciated. I'm keen on keeping my project as efficient as possible while taking advantage of the Edge Runtime's performance benefits.

Thank you in advance for your support!

`
1 of 1 error
Next.js (15.1.4) out of date [(learn more)](https://nextjs.org/docs/messages/version-staleness) (Turbopack)
Server Error

Error: The edge runtime does not support Node.js 'stream' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Object.get
node_modules/.pnpm/next@15.1.4_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/next/dist/src/server/web/globals.ts (69:13)
push.[project]/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/streams.js [middleware] (ecmascript).module.exports
node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/streams.js (19:64)
Object.enableStreamingAPI
node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/index.js (144:19)
[project]/node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/index.js [middleware] (ecmascript)
node_modules/.pnpm/iconv-lite@0.6.3/node_modules/iconv-lite/lib/index.js (169:11)

[turbopack]/browser/runtime/base/dev-base.ts (205:21)
runModuleExecutionHooks
[turbopack]/browser/runtime/base/dev-base.ts (264:5)
instantiateModule
[turbopack]/browser/runtime/base/dev-base.ts (203:5)
getOrInstantiateModuleFromParent
[turbopack]/browser/runtime/base/dev-base.ts (132:10)
commonJsRequire
[turbopack]/shared/runtime-utils.ts (241:18)
[project]/node_modules/.pnpm/mysql2@3.12.0/node_modules/mysql2/lib/parsers/string.js [middleware] (ecmascript)
node_modules/.pnpm/mysql2@3.12.0/node_modules/mysql2/lib/parsers/string.js (3:7)
Hide ignored frames
`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.