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:
co-authored by
Claude Sonnet 5
parent
671857722d
commit
fbfaf528ab
@@ -49,6 +49,13 @@ RUN apk upgrade --no-cache && \
|
|||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
# next/dist/lib/metadata/** (get-metadata-route.js and its neighbours). A
|
||||||
|
# plain top-level require in router-utils/filesystem.js, yet Next's own
|
||||||
|
# output file tracing for `output: "standalone"` + `next build --webpack`
|
||||||
|
# drops the whole directory - the server crashes on its first line with
|
||||||
|
# "Cannot find module '../../../lib/metadata/get-metadata-route'" without
|
||||||
|
# this. Same tracing-gap class as the plugins copy below.
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/next/dist/lib/metadata ./node_modules/next/dist/lib/metadata
|
||||||
# Staged first-party plugin bundles. Read by path at runtime, so Next's output
|
# Staged first-party plugin bundles. Read by path at runtime, so Next's output
|
||||||
# file tracing does not carry them into .next/standalone - copy explicitly or
|
# file tracing does not carry them into .next/standalone - copy explicitly or
|
||||||
# the image boots with the S/MIME policy toggle on and no plugin installed.
|
# the image boots with the S/MIME policy toggle on and no plugin installed.
|
||||||
|
|||||||
@@ -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);
|
console.log("Assembled standalone server at", standaloneDir);
|
||||||
|
|||||||
Reference in New Issue
Block a user