Skip to content

Commit 92cbfd3

Browse files
Add additional bullet for proxy
Co-authored-by: Joseph <[email protected]>
1 parent 3f0e949 commit 92cbfd3

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

crates/next-core/src/middleware.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,18 @@ impl Issue for MiddlewareMissingExportIssue {
184184
let relative_path_str = self.get_relative_path();
185185
let type_description = self.get_type_description();
186186

187+
let migration_bullet = if self.file_type.as_str() == "Proxy" {
188+
"- You are migrating from `middleware` to `proxy`, but haven't updated the exported \
189+
function.\n"
190+
} else {
191+
""
192+
};
193+
187194
// Rest of the message goes in description to avoid formatIssue indentation
188195
let description_text = format!(
189196
"This function is what Next.js runs for every request handled by this {}.\n\n\
190197
Why this happens:\n\
198+
{}\
191199
- The file exists but doesn't export a function.\n\
192200
- The export is not a function (e.g., an object or constant).\n\
193201
- There's a syntax error preventing the export from being recognized.\n\n\
@@ -197,6 +205,7 @@ impl Issue for MiddlewareMissingExportIssue {
197205
- Restart the dev server if the error persists.\n\n\
198206
Learn more: https://nextjs.org/docs/messages/middleware-to-proxy",
199207
type_description,
208+
migration_bullet,
200209
relative_path_str,
201210
self.function_name
202211
);

packages/next/src/build/analysis/get-page-static-info.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ function validateMiddlewareProxyExports({
403403
`The file "${relativeFilePath}" must export a function, either as a default export or as a named "${fileName}" export.\n` +
404404
`This function is what Next.js runs for every request handled by this ${fileName === 'proxy' ? 'proxy (previously called middleware)' : 'middleware'}.\n\n` +
405405
`Why this happens:\n` +
406+
(isProxy
407+
? "- You are migrating from `middleware` to `proxy`, but haven't updated the exported function.\n"
408+
: '') +
406409
`- The file exists but doesn't export a function.\n` +
407410
`- The export is not a function (e.g., an object or constant).\n` +
408411
`- There's a syntax error preventing the export from being recognized.\n\n` +

packages/next/src/build/templates/middleware.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ if (typeof handler !== 'function') {
2929
`The file "${resolvedRelativeFilePath}" must export a function, either as a default export or as a named "${fileName}" export.\n` +
3030
`This function is what Next.js runs for every request handled by this ${fileName === 'proxy' ? 'proxy (previously called middleware)' : 'middleware'}.\n\n` +
3131
`Why this happens:\n` +
32+
(isProxy
33+
? "- You are migrating from `middleware` to `proxy`, but haven't updated the exported function.\n"
34+
: '') +
3235
`- The file exists but doesn't export a function.\n` +
3336
`- The export is not a function (e.g., an object or constant).\n` +
3437
`- There's a syntax error preventing the export from being recognized.\n\n` +

test/e2e/app-dir/proxy-missing-export/proxy-missing-export.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const errorMessage = `The file "./proxy.ts" must export a function, either as a
66
This function is what Next.js runs for every request handled by this proxy (previously called middleware).
77
88
Why this happens:
9+
- You are migrating from \`middleware\` to \`proxy\`, but haven't updated the exported function.
910
- The file exists but doesn't export a function.
1011
- The export is not a function (e.g., an object or constant).
1112
- There's a syntax error preventing the export from being recognized.

0 commit comments

Comments
 (0)