Skip to content

Commit 9d45ee8

Browse files
authored
error-msg (#307)
1 parent ac52954 commit 9d45ee8

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
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 of getCloudflareContext
6+
7+
Hardcode function names that would get mangled otherwise.

examples/bugs/gh-219/next.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4-
/* config options here */
4+
eslint: {
5+
// Warning: This allows production builds to successfully complete even if
6+
// your project has ESLint errors.
7+
ignoreDuringBuilds: true,
8+
},
59
};
610

711
export default nextConfig;

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)