N Next.js 中文
原文 ↗

enablePrerenderSourceMaps

在 next build 期间为预渲染时的错误启用 source map。

更新于 2026-09-29Next.js 16.4.6

enablePrerenderSourceMaps 选项让 Node.js 在 next build 的预渲染阶段使用已有的 source map。当 source map 可用时,错误堆栈跟踪会指向原始源代码。其默认值为 true。

此选项不会生成 source map。Webpack 默认不会生成服务器端 source map。若要在排查预渲染错误时生成它们,请使用 next build --debug-prerender。

要禁用它,请将 enablePrerenderSourceMaps 设置为 false:

TypeScript

next.config.tsts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  enablePrerenderSourceMaps: false,
}

export default nextConfig

JavaScript

next.config.jsjs
/** @type {import('next').NextConfig} */
const nextConfig = {
  enablePrerenderSourceMaps: false,
}

module.exports = nextConfig

参考

选项 类型 默认值
enablePrerenderSourceMaps boolean true

在预渲染期间禁用 source map 可以减少构建内存占用,但会让预渲染错误更难调试。

版本历史

版本 变更
v16.3.0 默认值改为 true,无论是否启用了 cacheComponents。
v16.0.0 enablePrerenderSourceMaps 从 experimental.enablePrerenderSourceMaps 移至顶层 enablePrerenderSourceMaps 选项。