Skip to content

db-sqlite is pulling drizzle-kit/api into OpenNext Cloudflare output #16470

@clearfram3

Description

@clearfram3

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

https://github.com/clearfram3/payloadcms-db-issue

Reproduction Steps

  1. Clone the linked reproduction repository.

  2. Install dependencies:

    pnpm install
  3. Copy the example environment file:

    cp .env.example .env
  4. Build with OpenNext Cloudflare:

    pnpm opennext:build
  5. The build reaches the OpenNext server bundling phase and fails with errors like:

    ERROR: Could not resolve "drizzle-kit-8c53b399dac79e94/api"
  6. The intermediate Next output also contains drizzle-kit/api in 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    db: sqlite@payloadcms/db-sqliteplugin: otherOther plugins not listedstatus: needs-triagePossible bug which hasn't been reproduced yetv3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions