{"record":{"id":"4a0340db15724b87","repo":"vercel/next.js","slug":"default-export-is-missing-in-resource-path","errorCode":null,"errorMessage":"Default export is missing in {resource_path}","messagePattern":"Default export is missing in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/next-core/src/next_app/metadata/route.rs","lineNumber":236,"sourceCode":"    let stem = stem.unwrap_or_default();\n\n    let content_type = get_content_type(path.clone()).await?;\n\n    // refer https://github.com/vercel/next.js/blob/7b2b9823432fb1fa28ae0ac3878801d638d93311/packages/next/src/build/webpack/loaders/next-metadata-route-loader.ts#L84\n    // for the original template.\n    let code = formatdoc! {\n        r#\"\n            import {{ NextResponse }} from 'next/server'\n            import handler from {resource_path}\n            import {{ resolveRouteData }} from\n'next/dist/build/webpack/loaders/metadata/resolve-route-data'\n\n            const contentType = {content_type}\n            const cacheControl = {cache_control}\n            const fileType = {file_type}\n\n            if (typeof handler !== 'function') {{\n                throw new Error('Default export is missing in {resource_path}')\n            }}\n\n            export async function GET() {{\n              const data = await handler()\n              const content = resolveRouteData(data, fileType)\n\n              return new NextResponse(content, {{\n                headers: {{\n                  'Content-Type': contentType,\n                  'Cache-Control': cacheControl,\n                }},\n              }})\n            }}\n\n            export * from {resource_path}\n        \"#,\n        resource_path = StringifyJs(&format!(\"./{}\", path.file_name())),\n        content_type = StringifyJs(&content_type),","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/crates/next-core/src/next_app/metadata/route.rs#L218-L254","documentation":"Emitted at request time inside the JavaScript that Turbopack generates for a text-based App Router metadata route (e.g. app/robots.ts, app/manifest.ts, app/sitemap.xml without generateSitemaps, app/icon). The generated wrapper imports the route module's default export as `handler` and checks `typeof handler !== 'function'`; if the file has no default-exported function, it throws. Metadata route handlers must default-export a function that returns the route's data.","triggerScenarios":"A metadata route file (app/robots.ts, app/manifest.ts, app/sitemap.xml, app/<name>.txt) that exports only named exports, has no default export, or default-exports a non-function (object, string).","commonSituations":"Copying a Pages Router API route pattern (named exports); writing a config object instead of a function; forgetting the default export; refactoring that renamed/removed it.","solutions":["Add a default-exported function to the metadata route file that returns the route data.","Confirm the file is a recognized metadata route (correct filename: robots, manifest, sitemap, icon, apple-icon, etc.).","Ensure the default export is a function, not an object or constant."],"exampleFix":"// before: app/robots.ts\nexport const metadata = { rules: [] }\n\n// after: app/robots.ts\nexport default function(): MetadataRoute.Robots {\n  return { rules: [{ userAgent: '*', allow: '/' }] }\n}","handlingStrategy":"validation","validationCode":"// Validate a metadata route file has a default function export at author time\n// (run in a lint rule or pre-build check)\nfunction assertMetadataDefaultExport(moduleSource: string, file: string) {\n  if (!/export\\s+default\\s+(async\\s+)?function/.test(moduleSource)) {\n    throw new Error(`${file}: metadata route must default-export a function`)\n  }\n}","typeGuard":"const isFunction = (v: unknown): v is (...a: any[]) => any =>\n  typeof v === 'function'","tryCatchPattern":"null","preventionTips":["Always default-export a function from metadata route files (robots, manifest, sitemap, icon).","Use the MetadataRoute.* TypeScript types which enforce the function signature.","Add a lint rule that flags metadata route files missing a default function export."],"tags":["metadata-routes","app-router","turbopack","build"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}