This commit is contained in:
T. Narantuya 2025-09-11 17:11:58 +09:00
parent bef5abcbda
commit 449ec05d47

View File

@ -2,7 +2,7 @@
/* eslint-env node */
// Ensure dev-time Next.js manifests exist to avoid noisy ENOENT errors
import { mkdirSync, existsSync, writeFileSync } from "fs";
import { mkdirSync, existsSync, writeFileSync, rmSync } from "fs";
import { join } from "path";
import { URL } from "node:url";
/* global console */
@ -10,9 +10,28 @@ import { URL } from "node:url";
const root = new URL("..", import.meta.url).pathname; // apps/portal
const nextDir = join(root, ".next");
const routesManifestPath = join(nextDir, "routes-manifest.json");
const serverDir = join(nextDir, "server");
const vendorChunksDir = join(serverDir, "vendor-chunks");
const webpackRuntimePath = join(serverDir, "webpack-runtime.js");
try {
// Ensure .next exists
mkdirSync(nextDir, { recursive: true });
// Proactively clear stale vendor chunks to avoid version-mismatch runtime errors
// e.g. Cannot find module './vendor-chunks/zod@x.y.z.js'
try {
if (existsSync(vendorChunksDir)) {
rmSync(vendorChunksDir, { recursive: true, force: true });
console.log("[dev-prep] Cleared .next/server/vendor-chunks");
}
if (existsSync(webpackRuntimePath)) {
rmSync(webpackRuntimePath);
console.log("[dev-prep] Removed .next/server/webpack-runtime.js to force regeneration");
}
} catch (e) {
console.warn("[dev-prep] Failed to clear vendor-chunks:", e?.message || e);
}
if (!existsSync(routesManifestPath)) {
const minimalManifest = {
version: 5,