{"record":{"id":"244edd23bbac3a3b","repo":"microsoft/aspire","slug":"no-next-js-configuration-file-found-addnextjsapp-expects-one","errorCode":null,"errorMessage":"No Next.js configuration file found. AddNextJsApp expects one of: next.config.js, next.config.mjs, next.config.ts","messagePattern":"No Next\\.js configuration file found\\. AddNextJsApp expects one of: next\\.config\\.js, next\\.config\\.mjs, next\\.config\\.ts","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs","lineNumber":3188,"sourceCode":"\n                // Check for quoted \"standalone\" (double or single quotes) to reduce false positives\n                if (!content.Contains(\"\\\"standalone\\\"\") && !content.Contains(\"'standalone'\"))\n                {\n                    throw new InvalidOperationException(\n                        $\"The Next.js config file '{configFileName}' does not contain 'output: \\\"standalone\\\"'. \" +\n                        \"AddNextJsApp requires Next.js standalone output mode to generate a working Dockerfile. \" +\n                        \"Add 'output: \\\"standalone\\\"' to the nextConfig object in your Next.js config file.\");\n                }\n            }\n            catch (IOException)\n            {\n                // If we can't read the config, skip the check — the Docker build will surface the error.\n            }\n\n            return;\n        }\n\n        throw new InvalidOperationException(\n            \"No Next.js configuration file found. AddNextJsApp expects one of: \" +\n            string.Join(\", \", s_nextConfigFileNames));\n    }\n\n    private static void ValidateApiPath(string apiPath)\n    {\n        foreach (var c in apiPath)\n        {\n            if (!char.IsAsciiLetterOrDigit(c) && c is not '/' and not '-' and not '_')\n            {\n                throw new ArgumentException($\"The apiPath must contain only URL-safe path characters (alphanumeric, '/', '-', '_'). Invalid character: '{c}'\", nameof(apiPath));\n            }\n        }\n    }\n\n    /// <summary>\n    /// Walks up from <paramref name=\"startDirectory\"/> to find the nearest <c>node_modules</c> directory.\n    /// </summary>","sourceCodeStart":3170,"sourceCodeEnd":3206,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs#L3170-L3206","documentation":"AddNextJsApp validates that the app directory contains one of the supported Next.js config files (next.config.js, next.config.mjs, next.config.ts) before it can check for standalone output and generate a Dockerfile. If none of the expected filenames exist in the app's source directory, it throws this InvalidOperationException.","triggerScenarios":"Calling AddNextJsApp pointing at a directory that has no next.config.js/.mjs/.ts (e.g. wrong working directory, config named differently, or config located in a subdirectory).","commonSituations":"Pointing AddNextJsApp at the repo root instead of the Next.js app folder; an app that hasn't been initialized with create-next-app; a custom config filename not in s_nextConfigFileNames.","solutions":["Create a Next.js config file (next.config.js, next.config.mjs, or next.config.ts) in the app directory you pass to AddNextJsApp.","Verify the AddNextJsApp source directory argument points at the folder containing the config (not a parent or sibling).","If you use a custom config filename, rename it to one of the three supported names."],"exampleFix":"// before\nbuilder.AddNextJsApp(\"web\", \"./frontend/web\"); // no config file in ./frontend/web\n// after — ensure ./frontend/web/next.config.mjs exists:\n// export default { output: \"standalone\" };\nbuilder.AddNextJsApp(\"web\", \"./frontend/web\");","handlingStrategy":"validation","validationCode":"var configExists = new[] { \"next.config.js\", \"next.config.mjs\", \"next.config.ts\" }\n    .Any(f => File.Exists(Path.Combine(appDir, f)));\nif (!configExists) throw new InvalidOperationException(\"No next.config.* found in \" + appDir);","typeGuard":null,"tryCatchPattern":"try { builder.AddNextJsApp(\"web\", appDir); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"No Next.js configuration file found\")) { /* fix directory or create config */ }","preventionTips":["Point AddNextJsApp at the exact app folder containing next.config.*.","Initialize apps with create-next-app before wiring them into Aspire.","Add a directory-existence and config-file check in a shared builder helper."],"tags":["javascript","nextjs","file-not-found","config"],"backgroundTag":"config-file-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}