diff --git a/.changeset/nervous-pumpkins-try.md b/.changeset/nervous-pumpkins-try.md new file mode 100644 index 00000000..9d7caa81 --- /dev/null +++ b/.changeset/nervous-pumpkins-try.md @@ -0,0 +1,7 @@ +--- +"@opennextjs/cloudflare": patch +--- + +fix the error message of getCloudflareContext + +Hardcode function names that would get mangled otherwise. diff --git a/examples/bugs/gh-219/next.config.ts b/examples/bugs/gh-219/next.config.ts index e9ffa308..d65c117c 100644 --- a/examples/bugs/gh-219/next.config.ts +++ b/examples/bugs/gh-219/next.config.ts @@ -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; diff --git a/packages/cloudflare/src/api/cloudflare-context.ts b/packages/cloudflare/src/api/cloudflare-context.ts index 6a71c503..27e63651 100644 --- a/packages/cloudflare/src/api/cloudflare-context.ts +++ b/packages/cloudflare/src/api/cloudflare-context.ts @@ -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" ); }