workerd specific code
Configuration
workerd (opens in a new tab) is the runtime cloudflare uses to run Workers code.
While the nodejs_compat (opens in a new tab) flag makes workerd mostly compatible with Node.js,
there are still minor differences. Some packages publish code for different runtimes to account for those differences. For example, postgres has conditional exports (opens in a new tab) in its package.json (opens in a new tab):
"exports": {
"types": "./types/index.d.ts",
"bun": "./src/index.js",
"workerd": "./cf/src/index.js",
"import": "./src/index.js",
"default": "./cjs/src/index.js"
},With such exports, Node.js applications use either src/index.js or cjs/src/index.js depending if the app use ESM or CJS.
However we want to use the workerd specific entrypoint when using the Cloudflare adapter.
The adapter uses the workerd build of the packages that Next.js does not bundle. Since @opennextjs/cloudflare 1.20.15, this applies to all of them (and to their dependencies): the packages listed in serverExternalPackages and the packages that Next.js keeps external by default (opens in a new tab) (i.e. pg or @prisma/client). Before 1.20.15, only the packages listed in serverExternalPackages were using their workerd build.
Next.js bundles the other packages with the Node.js conditions. For those, you need to instruct Next.js not to bundle them by adding them to the serverExternalPackages key of your next.config.ts:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
serverExternalPackages: ["@prisma/client", ".prisma/client", "postgres"],
};
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
initOpenNextCloudflareForDev();
export default nextConfig;Packages known to have workerd specific code
@libsql/isomorphic-ws@prisma/client(and the generated.prisma/client)josepostgresreact-textarea-autosize
Please report an issue on the adapter GH repository (opens in a new tab) to have packages added to this list.