Skip to content

Commit 12d385d

Browse files
authoredFeb 24, 2025
fix incorrect (sync) getCloudflareContext error message (#404)
1 parent db8969b commit 12d385d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎.changeset/warm-lizards-lick.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix incorrect (sync) `getCloudflareContext` error message
6+
7+
currently `getCloudflareContext` run in sync mode at the top level of a not static route
8+
gives a misleading error message saying that the function needs to be run in a not static
9+
route, the changes here correct this error message clarifying that the problem actually is

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ function getCloudflareContextSync<
118118
// normal global state so we throw with a helpful error message.
119119
if (inSSG()) {
120120
throw new Error(
121-
`\n\nERROR: \`getCloudflareContext\` has been called in a static route,` +
122-
` that is not allowed, this can be solved in different ways:\n\n` +
123-
` - call \`getCloudflareContext({async: true})\` to use the \`async\` mode\n` +
124-
` - avoid calling \`getCloudflareContext\` in the route\n` +
125-
` - make the route non static\n`
121+
`\n\nERROR: \`getCloudflareContext\` has been called in sync mode in either a static route or at the top level of a non-static one,` +
122+
` both cases are not allowed but can be solved by either:\n` +
123+
` - make sure that the call is not at the top level and that the route is not static\n` +
124+
` - call \`getCloudflareContext({async: true})\` to use the \`async\` mode\n` +
125+
` - avoid calling \`getCloudflareContext\` in the route\n`
126126
);
127127
}
128128

0 commit comments

Comments
 (0)