import type { NextConfig } from "next"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const here = dirname(fileURLToPath(import.meta.url)); // Dev-server origin whitelist. Next.js only consults this list during // `next dev`; the previous config dropped the protocol and relied on a bare // "127.0.0.1" string, which fails the cross-origin check the latest Next.js // applies (CR N4). We ship a default with both loopback hosts + http, and // allow deployments to extend via ALLOWED_DEV_ORIGINS=a,b,c. const defaultDevOrigins = ["127.0.0.1", "localhost", "11.167.59.67"]; const extraDevOrigins = (process.env.ALLOWED_DEV_ORIGINS ?? "") .split(",") .map((origin) => origin.trim()) .filter(Boolean); const nextConfig: NextConfig = { // Produce a self-contained server bundle so the CLI can ship a runtime // directory without shipping node_modules or requiring `next start`. output: "standalone", // Tracing must reach the monorepo root to include workspace dependencies // (shared / sdk) that live outside dashboard/. outputFileTracingRoot: join(here, ".."), // ali-oss transitively depends on urllib@2, which lazy-requires // `proxy-agent` only at runtime, and its internal EventEmitter-based HTTP // client ships listeners that Turbopack's static analysis / code-splitting // can rewrite into non-callable references. When those listeners fire on // the tail end of a request (response / close events), the runtime throws // `TypeError: e.call is not a function` as an unhandledRejection — the // HTTP call itself already succeeded, so only the log is polluted. // // The fix is to take every Node-only package (and the workspace SDK that // re-exports them) out of the server bundle entirely, so Next's runtime // loads them via native `require()`. This matches how the CLI consumes the // same SDK and eliminates the class of issue rather than patching symptoms. serverExternalPackages: [ "@tablestore/tablestore-agent-sdk", "@tablestore/tablestore-agent-shared", "ali-oss", "urllib", "tablestore", "proxy-agent", ], outputFileTracingIncludes: { "/api/preview/pdfjs/**": [ "./node_modules/pdfjs-dist/package.json", "./node_modules/pdfjs-dist/build/pdf.worker.min.mjs", "./node_modules/pdfjs-dist/cmaps/**", "./node_modules/pdfjs-dist/standard_fonts/**", "./node_modules/pdfjs-dist/wasm/**", ], }, images: { unoptimized: true, }, allowedDevOrigins: Array.from( new Set([...defaultDevOrigins, ...extraDevOrigins]), ), }; export default nextConfig;