fix(build): copy next/dist/lib/metadata into standalone output

output: "standalone" + next build --webpack drops the whole metadata
directory despite a plain top-level require in router-utils/filesystem.js
("../../../lib/metadata/get-metadata-route") - every packaged build
(Electron dmg and the Docker image) crashed on its very first line with
Cannot find module. Verified: a fresh dist:mac build failed to boot at
all; copying the directory by hand (same pattern already used for the
sqlcipher prebuilds and plugin bundles) fixes it, confirmed by booting
.next/standalone directly and getting a real HTTP response.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Bernd Rodler
2026-08-07 12:50:33 +02:00
co-authored by Claude Sonnet 5
parent 671857722d
commit fbfaf528ab
2 changed files with 23 additions and 0 deletions
+16
View File
@@ -81,4 +81,20 @@ if (existsSync(pluginsSrc)) {
);
}
// next/dist/lib/metadata/** (get-metadata-route.js and its neighbours).
//
// router-utils/filesystem.js has a plain top-level `require("../../../lib/
// metadata/get-metadata-route")` - not dynamic, not conditional - yet Next's
// own output-file-tracing for `output: "standalone"` + `next build --webpack`
// drops the entire directory. Verified by inspecting a real build: the
// package was present, this one subfolder was missing, so the standalone
// server crashed on its very first line with "Cannot find module" - every
// packaged build (Electron and Docker) was affected. Same failure class as
// the sqlcipher prebuilds above: copy by hand what the tracer misses.
const metadataSrc = path.join(rootDir, "node_modules", "next", "dist", "lib", "metadata");
const metadataDest = path.join(standaloneDir, "node_modules", "next", "dist", "lib", "metadata");
rmSync(metadataDest, { recursive: true, force: true });
cpSync(metadataSrc, metadataDest, { recursive: true });
console.log("Copied next/dist/lib/metadata into the standalone output");
console.log("Assembled standalone server at", standaloneDir);