Repository navigation
Description
Describe the Bug
I’m using Payload with @payloadcms/db-sqlite, Next 16, and @opennextjs/cloudflare.
When building with OpenNext Cloudflare, drizzle-kit/api is reachable from the production server module graph. In a minimal reproduction, OpenNext fails while bundling the server function because it cannot resolve the rewritten drizzle-kit/api import:
ERROR: Could not resolve "drizzle-kit-8c53b399dac79e94/api"The path appears to be:
@payloadcms/db-sqlite
-> @payloadcms/drizzle/sqlite
-> requireDrizzleKit
-> require('drizzle-kit/api')The specific Payload path I’m looking at is:
// packages/db-sqlite/src/index.ts
import { requireDrizzleKit } from '@payloadcms/drizzle/sqlite'Then the adapter attaches requireDrizzleKit to the adapter object.
And then:
// packages/drizzle/src/sqlite/requireDrizzleKit.ts
const {
generateSQLiteDrizzleJson,
generateSQLiteMigration,
pushSQLiteSchema,
} = require('drizzle-kit/api')Since drizzle-kit/api is migration/schema tooling, I would not expect it to be reachable from the normal SQLite runtime adapter graph.
I’m already using withPayload, so this does not appear to be just a missing Next config wrapper issue:
// next.config.ts
import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare'
import { withPayload } from '@payloadcms/next/withPayload'
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
turbopack: {},
}
export default withPayload(nextConfig, { devBundleServerPackages: false })
initOpenNextCloudflareForDev()Payload config is the normal SQLite setup with sqliteAdapter and database credentials supplied by the environment:
db: sqliteAdapter({
client: {
url: databaseUrl,
authToken: databaseAuthToken,
},
})I saw the prior work around bundle size / transitive externalization in #14696 and #14845, so this may be an OpenNext Cloudflare edge case rather than plain next build.
Expected Behavior
I would expect drizzle-kit/api to stay out of the production runtime/server output unless migrations or schema generation are being run.
OpenNext Cloudflare should be able to bundle the production server output without needing migration/schema tooling from drizzle-kit/api.
What I’m unsure about
Is withPayload intended to keep drizzle-kit/api out of OpenNext Cloudflare production output, or should the SQLite adapter avoid importing/attaching requireDrizzleKit in a way that keeps migration tooling reachable from the runtime adapter graph?
Link to the code that reproduces this issue
Reproduction Steps
-
Clone the linked reproduction repository.
-
Install dependencies:
pnpm install
-
Copy the example environment file:
cp .env.example .env
-
Build with OpenNext Cloudflare:
pnpm opennext:build
-
The build reaches the OpenNext server bundling phase and fails with errors like:
ERROR: Could not resolve "drizzle-kit-8c53b399dac79e94/api"
-
The intermediate Next output also contains
drizzle-kit/apiin the traced server files:rg "drizzle-kit/api|drizzle-kit-.*api|generateSQLiteMigration|pushSQLiteSchema" .next .open-next
Which area(s) are affected?
db: sqlite, plugin: other
Environment Info
Binaries:
Node: 22.18.0
npm: 11.7.0
Yarn: N/A
pnpm: 10.33.0
Relevant Packages:
payload: 3.84.1
next: 16.2.4
@payloadcms/db-sqlite: 3.84.1
@payloadcms/drizzle: 3.84.1
@payloadcms/email-nodemailer: 3.84.1
@payloadcms/graphql: 3.84.1
@payloadcms/next/utilities: 3.84.1
@payloadcms/payload-cloud: 3.84.1
@payloadcms/richtext-lexical: 3.84.1
@payloadcms/translations: 3.84.1
@payloadcms/ui/shared: 3.84.1
react: 19.2.0
react-dom: 19.2.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8122
Available memory (MB): 16384
Available CPU cores: 8
Activity
celestial-rose commentedon May 11, 2026
+1; I got the exact same behavior when deploying to Workers using OpenNext, Payload 3.84.1 + NextJS 16.2.4 though im using the
@payloadcms/db-d1-sqliteadapter, same errorPS : amazing issue write-up, it has everything
francoiscote commentedon May 14, 2026
temporary workaround for me has been to add
@payloadcms/drizzle/sqliteto theserverExternalPackagesoption innext.config.ts.celestial-rose commentedon May 15, 2026
thanks for the tip @francoiscote ! worked perfect, but then I had to also update
@opennextbecause I had this error in runtime (not during build)Unexpected loadManifest(/.next/server/prefetch-hints.json) call!After updating the
@opennextversion to latest (thanks to opennextjs/opennextjs-cloudflare#1157), I had a new build error onjosefrom payloadI knew there would be errors after
@opennextupgrade when I saw this release that added changes to the wayserverExternalPackagesis handled : https://github.com/opennextjs/opennextjs-cloudflare/releases/tag/%40opennextjs%2Fcloudflare%401.19.2Anywho, don't know if it was the good thing to do, but I also added
joseto theserverExternalPackagesand all seems to work now !clearfram3 commentedon May 27, 2026
Has the latest 16.3 canary or opennext releases fixed this for anyone?
AndreasGalster2 commentedon Jul 23, 2026
Only solution for me was using webpack and
Not really perfect, so hoping there'll be a fixed relatively soon. Payload on OpenNext/Cloudflare seems a bit all over the place to me.
LVLUP-Studio commentedon Jul 23, 2026
I got around it as well by using webpack instead of turbo.
fix(templates): fix with-cloudflare-d1 build and bump dependencies (#…
AndreasGalster2 commentedon Aug 3, 2026
Next 16.3 stable was just released.
https://github.com/vercel/next.js/releases/tag/v16.3.0
Would be worth re-evaluating a fix for this.
As far as I know, drizzle, which is currently RC.4, is also supposed to be the live version with RC.5. Hopefully this can be addressed in Payload 4 or even sooner so we can disable webpack/use turbopack.
Unfortunately, not resolved in 16.3.0 stable.
nathanlentz commentedon Aug 4, 2026
@AndreasGalster2 it's on the list! Looks like there are some changes to Turbopack in here which might help us out. Appreciate you connecting the release to this issue!
clearfram3 commentedon Aug 18, 2026
tbh ditching v3 and nextjs for v4+tanstack
AndreasGalster2 commentedon Sep 8, 2026
Any expectation when this may roll out? Beta v4?
nathanlentz commentedon Sep 9, 2026
My goal is to continue to work on Cloudflare compatibility as we roll through v4 beta. No hard date for you, but I am actively thinking about this.
fix: make the Cloudflare deploy actually build
fix(drizzle): lazily load drizzle kit tooling (#17656)
fix(drizzle): lazily load drizzle kit tooling (3.x) (#17660)
nathanlentz commentedon Oct 27, 2026
#17656 (main) and #17660 (3.x) should fix this issue and will ship in the next v4 beta release / 3.x release.
What Changed
Before, our adapters loaded
drizzle-kit/apiwithrequire(). Turbopack followed that import all the way into the production server output, so OpenNext tried to bundledrizzle-kit-<hash>/apiand failed. Now, Drizzle Kit loads lazily only when schema push or migration generation runs. The bundler won't follow that, so Drizzle Kit stays out of the runtime output . Applies todb-sqlite,db-d1-sqlite,db-postgres, anddb-vercel-postgres