Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/nervous-pumpkins-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/cloudflare": patch
---

fix the error message of getCloudflareContext

Hardcode function names that would get mangled otherwise.
6 changes: 5 additions & 1 deletion examples/bugs/gh-219/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
};

export default nextConfig;
19 changes: 8 additions & 11 deletions packages/cloudflare/src/api/cloudflare-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,17 @@ export function getCloudflareContext<
// the cloudflare context is initialized by the worker and is always present in production/preview
// during local development (`next dev`) it might be missing only if the developers hasn't called
// the `initOpenNextCloudflareForDev` function in their Next.js config file
const getContextFunctionName = getCloudflareContext.name;
const initFunctionName = initOpenNextCloudflareForDev.name;
throw new Error(
`\n\n\`${getContextFunctionName}\` has been called during development without having called` +
` the \`${initFunctionName}\` function inside the Next.js config file.\n\n` +
`In order to use \`${getContextFunctionName}\` import and call ${initFunctionName} in the Next.js config file.\n\n` +
"Example: \n ```\n // next.config.mjs\n\n" +
` import { ${initFunctionName} } from "@opennextjs/cloudflare";\n\n` +
` ${initFunctionName}();\n\n` +
" /** @type {import('next').NextConfig} */\n" +
" const nextConfig = {};\n" +
`\n\nERROR: \`getCloudflareContext\` has been called without having called` +
` \`initOpenNextCloudflareForDev\` from the Next.js config file.\n` +
`You should update your Next.js config file as shown below:\n\n` +
" ```\n // next.config.mjs\n\n" +
` import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";\n\n` +
` initOpenNextCloudflareForDev();\n\n` +
" const nextConfig = { ... };\n" +
" export default nextConfig;\n" +
" ```\n" +
"\n(note: currently middlewares in Next.js are always run using the edge runtime)\n\n"
"\n"
);
}

Expand Down