NNext.js 中文网 GitHub

enablePrerenderSourceMaps

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

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

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

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

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

const nextConfig: NextConfig = {
  enablePrerenderSourceMaps: false,
}

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

module.exports = nextConfig

参考#

选项类型默认值
enablePrerenderSourceMapsbooleantrue

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

版本历史#

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