Skip to content

Commit 79fadc4

Browse files
authored
Log exceptions in requirePage and NodeModuleLoader in debug mode (#522)
1 parent 19dedc7 commit 79fadc4

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

.changeset/fast-goats-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
Log exceptions in `requirePage` and `NodeModuleLoader` when `OPEN_NEXT_DEBUG=1`

packages/cloudflare/src/cli/build/patches/plugins/dynamic-requires.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ rule:
9494
regex: ^NodeModuleLoader$
9595
fix: |
9696
async load($ID) {
97-
${getRequires("$ID", files, serverDir)}
97+
${
98+
buildOpts.debug
99+
? ` try {
100+
${getRequires("$ID", files, serverDir)}
101+
} catch (e) {
102+
console.error('Exception in NodeModuleLoader', e);
103+
throw e;
104+
}`
105+
: getRequires("$ID", files, serverDir)
106+
}
98107
}`;
99108
}
100109

@@ -135,7 +144,16 @@ function requirePage($PAGE, $DIST_DIR, $IS_APP_PATH) {
135144
process.env.__NEXT_PRIVATE_RUNTIME_TYPE = $IS_APP_PATH ? 'app' : 'pages';
136145
try {
137146
${getRequires("pagePath", jsFiles, serverDir)}
138-
} finally {
147+
} ${
148+
buildOpts.debug
149+
? `
150+
catch (e) {
151+
console.error("Exception in requirePage", e);
152+
throw e;
153+
}`
154+
: ``
155+
}
156+
finally {
139157
process.env.__NEXT_PRIVATE_RUNTIME_TYPE = '';
140158
}
141159
}`,

0 commit comments

Comments
 (0)