Renaming the distDir and using "output: export" seems to render "npm run start" unusable
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/npm-run-start-broken-t9z2fd
To Reproduce
- I start clean by deleting both the
.nextandbuildfolders if present. - Run the "build" task; this runs
npm run buildwhich runsnext build .nextandbuildfolders are created successfully. Run the "prod" task; this runsnpm run startwhich runsnext start- Error propagates
Current vs. Expected behavior
I am trying to test my production build locally. We are using static exports for our application and we have renamed the typical "out" folder to "build" in next.config.mjs. Everything builds successfully (and I have deployed it on production just fine), but running npm run start (which is really next start) cannot seem to find the production build.
I get this error:
Error: Could not find a production build in the 'build' directory.
Try building your app with 'next build' before starting the production server.
https://nextjs.org/docs/messages/production-start-no-build-id
This is my next.config.mjs file:
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
distDir: 'build',
reactStrictMode: false,
images: {
unoptimized: true,
},
}
export default nextConfig
The .next folder seems to contain the BUILD_ID but the build folder, which contains all the static exports, does not have a BUILD_ID and I think that is what npm run start is looking for based on the URL the error message points to. Any suggestions on how to run the production build with npm run start?
I understand my environment info below dictates things are out of date, but my codesandbox above should be using the latest NextJS and it still doesn't work there.
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Thu Nov 7 15:41:49 EST 2024
Available memory (MB): 15736
Available CPU cores: 4
Binaries:
Node: 20.5.1
npm: 9.8.1
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.2.16 // An outdated version detected (latest is 15.0.3), upgrade is highly recommended!
eslint-config-next: 14.2.16
react: 18.3.1
react-dom: 18.3.1
typescript: 5.5.3
Next.js Config:
output: export
⚠ An outdated version detected (latest is 15.0.3), upgrade is highly recommended!
Which area(s) are affected? (Select all that apply)
Developer Experience
Which stage(s) are affected? (Select all that apply)
next start (local)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox and its next.config.mjs, then run the reported npm run build and npm run start commands after removing .next and build. Inspect how output: export and distDir: 'build' affect the generated directories and production-start lookup. Done means the reported local production workflow has a documented or verified outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js, react
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100