nitro icon indicating copy to clipboard operation
nitro copied to clipboard

`event.context.nitro` in undefined in CF pages

Open farnabaz opened this issue 2 months ago • 0 comments

Environment

- Operating System: Darwin
- Node Version:     v20.11.1
- Nuxt Version:     3.12.1
- CLI Version:      3.12.0
- Nitro Version:    2.10.0-28638494.93d002b7
- Package Manager:  [email protected]

Reproduction

Live: https://7b85d7f1.nuxthub.pages.dev/ Faced on https://github.com/nuxt-hub/platform/pull/203

Describe the bug

Deploying project to Cloudflare pages result undefined error because event.context.nitro is undefined.

I made a little patch that handles the undefined error. This might not be the correct solution for this issue but as a workaround it works fine

diff --git a/dist/runtime/internal/config.mjs b/dist/runtime/internal/config.mjs
index f4314c748192ce0fe2fd72bb61de28fa8b70f1eb..c8c508297723568bbc1b817b14c89f1d691868a7 100644
--- a/dist/runtime/internal/config.mjs
+++ b/dist/runtime/internal/config.mjs
@@ -14,11 +14,12 @@ export function useRuntimeConfig(event) {
   if (!event) {
     return _sharedRuntimeConfig;
   }
-  if (event.context.nitro.runtimeConfig) {
+  if (event.context.nitro?.runtimeConfig) {
     return event.context.nitro.runtimeConfig;
   }
   const runtimeConfig = klona(_inlineRuntimeConfig);
   applyEnv(runtimeConfig, envOptions);
+  event.context.nitro = event.context.nitro || {};
   event.context.nitro.runtimeConfig = runtimeConfig;
   return runtimeConfig;
 }

Additional context

No response

Logs

No response

farnabaz avatar Jun 14 '24 11:06 farnabaz