fix: improve error message for missing exports in file routes (#3718)
Closes #3652 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
4e0331b5c9
commit
059183b230
@@ -310,8 +310,11 @@ export function validateFsMod<State>(
|
||||
mod: FreshFsMod<State>;
|
||||
} {
|
||||
if (!isFreshFile<State>(mod, commandType)) {
|
||||
const hint = commandType === CommandType.Middleware
|
||||
? `Middleware files must have a default export (function or array of functions).\n\n Example:\n export default define.middleware(async (ctx) => {\n return await ctx.next();\n });`
|
||||
: `Route files must export a default component, a "handler" or "handlers" export, or a "config" export.\n\n Example:\n export const handler = define.handlers({ GET(ctx) { ... } });\n export default define.page((props) => <h1>Hello</h1>);`;
|
||||
throw new Error(
|
||||
`Expected a route, middleware, layout or error template, but couldn't find relevant exports in: ${filePath}`,
|
||||
`Could not find relevant exports in: ${filePath}\n\n${hint}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user