Skip to content

Commit a281e1c

Browse files
committed
fix the error message of getCloudflareContext
1 parent ac52954 commit a281e1c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

.changeset/nervous-pumpkins-try.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix the error message for getCloudflareContext
6+
7+
Hardcode function names that would get mangled otherwise.

packages/cloudflare/src/api/cloudflare-context.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,17 @@ export function getCloudflareContext<
6262
// the cloudflare context is initialized by the worker and is always present in production/preview
6363
// during local development (`next dev`) it might be missing only if the developers hasn't called
6464
// the `initOpenNextCloudflareForDev` function in their Next.js config file
65-
const getContextFunctionName = getCloudflareContext.name;
66-
const initFunctionName = initOpenNextCloudflareForDev.name;
6765
throw new Error(
68-
`\n\n\`${getContextFunctionName}\` has been called during development without having called` +
69-
` the \`${initFunctionName}\` function inside the Next.js config file.\n\n` +
70-
`In order to use \`${getContextFunctionName}\` import and call ${initFunctionName} in the Next.js config file.\n\n` +
71-
"Example: \n ```\n // next.config.mjs\n\n" +
72-
` import { ${initFunctionName} } from "@opennextjs/cloudflare";\n\n` +
73-
` ${initFunctionName}();\n\n` +
74-
" /** @type {import('next').NextConfig} */\n" +
75-
" const nextConfig = {};\n" +
66+
`\n\nERROR: \`getCloudflareContext\` has been called without having called` +
67+
` \`initOpenNextCloudflareForDev\` from the Next.js config file.\n` +
68+
`You should update your Next.js config file as shown below:\n\n` +
69+
" ```\n // next.config.mjs\n\n" +
70+
` import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";\n\n` +
71+
` initOpenNextCloudflareForDev();\n\n` +
72+
" const nextConfig = { ... };\n" +
7673
" export default nextConfig;\n" +
7774
" ```\n" +
78-
"\n(note: currently middlewares in Next.js are always run using the edge runtime)\n\n"
75+
"\n"
7976
);
8077
}
8178

0 commit comments

Comments
 (0)