mirror of
https://github.com/tiennm99/vngeoguessr.git
synced 2026-10-11 03:13:56 +00:00
next dev and next build both own the output directory, so building while a dev server is serving replaces manifests that server is still reading. It logs a burst of ENOENT errors for those manifests, including paths under pages/_app that this App Router project has no reason to touch, which makes it look like the code being edited is at fault. Measured: 110 such errors from one overlapping build, none when they do not overlap. build:check builds into a separate directory and leaves a running dev server alone. The build script itself is untouched, because that is what the deployment platform runs and it must keep writing the default directory; distDir only moves when the new script sets the variable. dev:clean covers the other trap: a build cache left inconsistent by a killed build or a different Next version makes the dev server serve 500s for everything, and restarting does not help while the cache is still there. Also records what actually needs a restart, which is nothing: routes, libs and data all hot reload, Next restarts itself for its config, and it reloads .env in place.
23 lines
835 B
JavaScript
23 lines
835 B
JavaScript
// Production build for local verification, into its own output directory.
|
|
//
|
|
// `next dev` and `next build` both own `.next`. Building while a dev server is
|
|
// serving makes that server read manifests the build has just replaced, which
|
|
// surfaces as a burst of ENOENT errors on files like
|
|
// `.next/server/app/page/app-build-manifest.json`. Measured: 110 such errors in
|
|
// one run, and none when the two do not overlap.
|
|
//
|
|
// The `build` script is left exactly as it is, because that is what the
|
|
// deployment platform runs and it must keep writing to `.next`.
|
|
//
|
|
// npm run build:check
|
|
|
|
import { spawn } from 'node:child_process';
|
|
|
|
const child = spawn('npx', ['next', 'build'], {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
env: { ...process.env, NEXT_DIST_DIR: '.next-check' },
|
|
});
|
|
|
|
child.on('exit', (code) => process.exit(code ?? 1));
|