microsoft/aspire · error · InvalidOperationException
The Next.js config file
Error message
The Next.js config file '{configFileName}' does not contain 'output: "standalone"'. AddNextJsApp requires Next.js standalone output mode to generate a working Dockerfile. Add 'output: "standalone"' to the nextConfig object in your Next.js config file. What it means
AddNextJsApp generates a Dockerfile that depends on Next.js standalone output (which emits a self-contained server into .next/standalone). The library reads the Next.js config file at model-build time and throws if it cannot find an 'output: "standalone"' setting, because without it the published container would not run.
Solutions
- Add output: "standalone" to the nextConfig object in next.config.js/.mjs/.ts.
- Quote the standalone value (output: "standalone" or output: 'standalone') — unquoted output: standalone will not satisfy the string check in some validation paths.
- Re-run the AppHost after saving the config change.
Example fix
// before (next.config.js)
const nextConfig = {};
// after
const nextConfig = { output: "standalone" }; Defensive patterns
Strategy: validation
Validate before calling
var config = File.ReadAllText(Path.Combine(appDir, "next.config.mjs"));
if (!config.Contains("\"standalone\"") && !config.Contains("'standalone'"))
throw new InvalidOperationException("next.config must set output: \"standalone\" (quoted)."); Try / catch
try { builder.AddNextJsApp("web", "./web"); } catch (InvalidOperationException ex) when (ex.Message.Contains("standalone")) { /* fix next.config and re-run */ } Prevention
- Scaffold Next.js apps with output: "standalone" in the config template.
- Keep the value quoted — the check matches quoted literals only.
- Validate configs in CI before running the AppHost.
When it happens
Trigger: Calling AddNextJsApp when next.config.js/.mjs/.ts exists but lacks output:"standalone" (or uses unquoted standalone — the check only matches "standalone" or 'standalone' literals, so output: standalone without quotes fails the Contains check).
Common situations: Scaffolding a new Next.js app with create-next-app (defaults to no standalone output); manually-written config with output: standalone unquoted (TypeScript-valid but fails this string check); config file unreadable is skipped, but a readable file missing the flag throws.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- No Next.js configuration file found. AddNextJsApp expects…
- The path must be a relative path.
- The path must not contain ".." segments.
- Error applying Aspire Vite configuration. Falling back to…
- The apiPath must contain only URL-safe path characters…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/fc3c9b8a3807bf95.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs:3174
/// </summary>
internal static void ValidateNextJsStandaloneOutput(string appDirectory)
{
foreach (var configFileName in s_nextConfigFileNames)
{
var configPath = Path.Combine(appDirectory, configFileName);
if (!File.Exists(configPath))
{
continue;
}
try
{
var content = File.ReadAllText(configPath);
// Check for quoted "standalone" (double or single quotes) to reduce false positives
if (!content.Contains("\"standalone\"") && !content.Contains("'standalone'"))
{
throw new InvalidOperationException(
$"The Next.js config file '{configFileName}' does not contain 'output: \"standalone\"'. " +
"AddNextJsApp requires Next.js standalone output mode to generate a working Dockerfile. " +
"Add 'output: \"standalone\"' to the nextConfig object in your Next.js config file.");
}
}
catch (IOException)
{
// If we can't read the config, skip the check — the Docker build will surface the error.
}
return;
}
throw new InvalidOperationException(
"No Next.js configuration file found. AddNextJsApp expects one of: " +
string.Join(", ", s_nextConfigFileNames));
}
View on GitHub (pinned to 25830f84bd)