Skip to content

Commit 621718e

Browse files
remove throwMissingInitOpenNextCloudflareForDevError function
1 parent 0fef012 commit 621718e

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function getCloudflareContextSync<
126126
);
127127
}
128128

129-
throwMissingInitOpenNextCloudflareForDevError();
129+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
130130
}
131131

132132
/**
@@ -154,25 +154,7 @@ async function getCloudflareContextAsync<
154154
return cloudflareContext;
155155
}
156156

157-
throwMissingInitOpenNextCloudflareForDevError();
158-
}
159-
160-
function throwMissingInitOpenNextCloudflareForDevError(): never {
161-
// In production the cloudflare context is initialized by the worker so it is always available.
162-
// During local development (`next dev`) it might be missing only if the developers hasn't called
163-
// the `initOpenNextCloudflareForDev` function in their Next.js config file
164-
throw new Error(
165-
`\n\nERROR: \`getCloudflareContext\` has been called without having called` +
166-
` \`initOpenNextCloudflareForDev\` from the Next.js config file.\n` +
167-
`You should update your Next.js config file as shown below:\n\n` +
168-
" ```\n // next.config.mjs\n\n" +
169-
` import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";\n\n` +
170-
` initOpenNextCloudflareForDev();\n\n` +
171-
" const nextConfig = { ... };\n" +
172-
" export default nextConfig;\n" +
173-
" ```\n" +
174-
"\n"
175-
);
157+
throw new Error(initOpenNextCloudflareForDevErrorMsg);
176158
}
177159

178160
/**
@@ -277,3 +259,18 @@ async function getCloudflareContextFromWrangler<
277259
ctx: ctx as Context,
278260
};
279261
}
262+
263+
// In production the cloudflare context is initialized by the worker so it is always available.
264+
// During local development (`next dev`) it might be missing only if the developers hasn't called
265+
// the `initOpenNextCloudflareForDev` function in their Next.js config file
266+
const initOpenNextCloudflareForDevErrorMsg =
267+
`\n\nERROR: \`getCloudflareContext\` has been called without having called` +
268+
` \`initOpenNextCloudflareForDev\` from the Next.js config file.\n` +
269+
`You should update your Next.js config file as shown below:\n\n` +
270+
" ```\n // next.config.mjs\n\n" +
271+
` import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";\n\n` +
272+
` initOpenNextCloudflareForDev();\n\n` +
273+
" const nextConfig = { ... };\n" +
274+
" export default nextConfig;\n" +
275+
" ```\n" +
276+
"\n";

0 commit comments

Comments
 (0)