From 964bf5aa407e942b5a79a0cb45598111c49f3f0a Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 1 Apr 2025 10:35:08 +0200 Subject: [PATCH 1/3] Log exceptions in requirePage when OPEN_NEXT_DEBUG=1 --- .changeset/fast-goats-fix.md | 5 +++++ .../src/cli/build/patches/plugins/dynamic-requires.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/fast-goats-fix.md diff --git a/.changeset/fast-goats-fix.md b/.changeset/fast-goats-fix.md new file mode 100644 index 00000000..83a4547f --- /dev/null +++ b/.changeset/fast-goats-fix.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/cloudflare": patch +--- + +Log excpetions in requirePage when OPEN_NEXT_DEBUG=1 diff --git a/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts b/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts index 310140fd..17467792 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts @@ -135,7 +135,16 @@ function requirePage($PAGE, $DIST_DIR, $IS_APP_PATH) { process.env.__NEXT_PRIVATE_RUNTIME_TYPE = $IS_APP_PATH ? 'app' : 'pages'; try { ${getRequires("pagePath", jsFiles, serverDir)} - } finally { + } ${ + buildOpts.debug + ? ` + catch (e) { + console.error(e); + throw e; + }` + : `` + } + finally { process.env.__NEXT_PRIVATE_RUNTIME_TYPE = ''; } }`, From 713533e3ce89b49bc630e1588077d463ed930ca6 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 1 Apr 2025 15:43:58 +0200 Subject: [PATCH 2/3] fixup: handle NodeModuleLoader --- .../src/cli/build/patches/plugins/dynamic-requires.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts b/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts index 17467792..c17f37a4 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts @@ -94,7 +94,12 @@ rule: regex: ^NodeModuleLoader$ fix: | async load($ID) { - ${getRequires("$ID", files, serverDir)} + try { + ${getRequires("$ID", files, serverDir)} + } catch (e) { + ${buildOpts.debug ? "console.error('Exception in NodeModuleLoader', e);" : ""} + throw e; + } }`; } @@ -139,7 +144,7 @@ function requirePage($PAGE, $DIST_DIR, $IS_APP_PATH) { buildOpts.debug ? ` catch (e) { - console.error(e); + console.error("Exception in requirePage", e); throw e; }` : `` From 14c18568441222684f4063f981d09ee099195d03 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 1 Apr 2025 15:49:25 +0200 Subject: [PATCH 3/3] fixup! --- .changeset/fast-goats-fix.md | 2 +- .../src/cli/build/patches/plugins/dynamic-requires.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.changeset/fast-goats-fix.md b/.changeset/fast-goats-fix.md index 83a4547f..6e534f41 100644 --- a/.changeset/fast-goats-fix.md +++ b/.changeset/fast-goats-fix.md @@ -2,4 +2,4 @@ "@opennextjs/cloudflare": patch --- -Log excpetions in requirePage when OPEN_NEXT_DEBUG=1 +Log exceptions in `requirePage` and `NodeModuleLoader` when `OPEN_NEXT_DEBUG=1` diff --git a/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts b/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts index c17f37a4..05d1e87d 100644 --- a/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts +++ b/packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts @@ -94,11 +94,15 @@ rule: regex: ^NodeModuleLoader$ fix: | async load($ID) { - try { + ${ + buildOpts.debug + ? ` try { ${getRequires("$ID", files, serverDir)} } catch (e) { - ${buildOpts.debug ? "console.error('Exception in NodeModuleLoader', e);" : ""} + console.error('Exception in NodeModuleLoader', e); throw e; + }` + : getRequires("$ID", files, serverDir) } }`; }