AddNpmApp does not build Next.js app before starting — missing '.next' build directory
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When using builder.AddNpmApp(...) with a Next.js frontend project (in production mode), Aspire fails to run the app because the production build is missing. The startup log shows:
`[Error: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id]
`
Even though WithNpmPackageInstallation() is present, it seems that next build is not executed automatically before npm start.
### Expected Behavior
Aspire should support typical production workflows for popular frontend frameworks like Next.js. If `npm start `requires next build, Aspire should either:
run `npm run build` automatically before npm start (when in production mode), or
encourage developers to specify `.WithBuildCommand("npm run build") `explicitly in documentation.
### Steps To Reproduce
builder.AddNpmApp("frontend", "../frontend")
.WithEnvironment("NODE_ENV", "production")
.WithNpmPackageInstallation()
.WithHttpEndpoint(env: "PORT")
.PublishAsDockerFile();
### Exceptions (if any)
[Error: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id]
### .NET Version info
_No response_
### Anything else?
.NET SDK:
Version: 9.0.301
Commit: a596cd22e2
Workload version: 9.0.300-manifests.07067f5b
MSBuild version: 17.14.5+edd3bbf37
Contributor guide
Assessment
This issue has not been assessed yet.