Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming the distDir and using "output: export" seems to render "npm run start" unusable #73051

Open
mkf62 opened this issue Nov 21, 2024 · 3 comments
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc.

Comments

@mkf62
Copy link

mkf62 commented Nov 21, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/npm-run-start-broken-t9z2fd

To Reproduce

  1. I start clean by deleting both the .next and build folders if present.
  2. Run the "build" task; this runs npm run build which runs next build
  3. .next and build folders are created successfully. Run the "prod" task; this runs npm run start which runs next start
  4. 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

@mkf62 mkf62 added the bug Issue was opened via the bug report template. label Nov 21, 2024
@github-actions github-actions bot added the Developer Experience Issues related to Next.js logs, Error overlay, etc. label Nov 21, 2024
@JesseKoldewijn
Copy link
Contributor

Hey there! Could you test the above against the latest canary release by chance?🙂

@mkf62
Copy link
Author

mkf62 commented Nov 21, 2024

The codesandbox I dropped in my OP is using the latest canary build I believe:
Screenshot 2024-11-21 at 12 09 12 PM

The same error occurs in that sandbox. Though, now I'm wondering if next start is even intended to work with static exports. It appears not after I stumbled upon the below.

I ended up just removing the distDir line in my next.config.mjs file so it would go back to default settings (producing an out folder). I then rebuilt the project and tried npm run start again and got this error message which gave me how to fix this issue:

Error: "next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.

Following that error, I installed serve with npm install serve --save-dev and used the command npx serve out and it worked. I then added back my old distDir: 'build' setting in next.config.mjs, rebuilt my project and tried npx serve build and that worked too.

Maybe the error message for using next start needs to be updated so if you change the distDir folder name with the output: export method defined, you get an more helpful error message like the above.

@JesseKoldewijn
Copy link
Contributor

Sounds about right. Just shouldn't install serve if you run it with box though, since box directly calls the package and won't use the locally installed version 🤙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc.
Projects
None yet
Development

No branches or pull requests

2 participants