nitrojs / nitrojs/nitro

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

Open
#2,531 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

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:  pnpm@9.1.3
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with dist/runtime/internal/config.mjs and the useRuntimeConfig(event) entry point shown in the report. Reproduce the deployment using the linked Cloudflare Pages example and inspect why event.context.nitro is absent. Done means runtime configuration no longer throws when that context is undefined, without relying only on an edited generated file.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.