microsoft/aspire · error · InvalidOperationException

No Next.js configuration file found. AddNextJsApp expects…

Error message

No Next.js configuration file found. AddNextJsApp expects one of: next.config.js, next.config.mjs, next.config.ts

What it means

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.

Solutions

  1. Create a Next.js config file (next.config.js, next.config.mjs, or next.config.ts) in the app directory you pass to AddNextJsApp.
  2. Verify the AddNextJsApp source directory argument points at the folder containing the config (not a parent or sibling).
  3. If you use a custom config filename, rename it to one of the three supported names.

Example fix

// before
builder.AddNextJsApp("web", "./frontend/web"); // no config file in ./frontend/web
// after — ensure ./frontend/web/next.config.mjs exists:
// export default { output: "standalone" };
builder.AddNextJsApp("web", "./frontend/web");
Defensive patterns

Strategy: validation

Validate before calling

var configExists = new[] { "next.config.js", "next.config.mjs", "next.config.ts" }
    .Any(f => File.Exists(Path.Combine(appDir, f)));
if (!configExists) throw new InvalidOperationException("No next.config.* found in " + appDir);

Try / catch

try { builder.AddNextJsApp("web", appDir); } catch (InvalidOperationException ex) when (ex.Message.Contains("No Next.js configuration file found")) { /* fix directory or create config */ }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/244edd23bbac3a3b. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs:3188

                // 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));
    }

    private static void ValidateApiPath(string apiPath)
    {
        foreach (var c in apiPath)
        {
            if (!char.IsAsciiLetterOrDigit(c) && c is not '/' and not '-' and not '_')
            {
                throw new ArgumentException($"The apiPath must contain only URL-safe path characters (alphanumeric, '/', '-', '_'). Invalid character: '{c}'", nameof(apiPath));
            }
        }
    }

    /// <summary>
    /// Walks up from <paramref name="startDirectory"/> to find the nearest <c>node_modules</c> directory.
    /// </summary>

View on GitHub (pinned to 25830f84bd)