experimental.browserDebugInfoInTerminal 选项将源自浏览器的控制台输出和运行时错误转发到开发服务器终端。
此选项默认禁用。启用时,它仅在开发模式下有效。
启用转发:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
browserDebugInfoInTerminal: true,
},
}
export default nextConfig/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
browserDebugInfoInTerminal: true,
},
}
module.exports = nextConfig深度嵌套的对象/数组会使用合理的默认值进行截断。您可以调整这些限制:
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
browserDebugInfoInTerminal: {
depthLimit: 5,
edgeLimit: 100,
},
},
}
export default nextConfig/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
browserDebugInfoInTerminal: {
depthLimit: 5,
edgeLimit: 100,
},
},
}
module.exports = nextConfig启用此功能后,默认包含源位置信息。
'use client'
export default function Home() {
return (
<button
type="button"
onClick={() => {
console.log('Hello World')
}}
>
Click me
</button>
)
}点击按钮会将此消息打印到终端。
[browser] Hello World (app/page.tsx:8:17)要抑制它们,请将 showSourceLocation: false。
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
experimental: {
browserDebugInfoInTerminal: {
showSourceLocation: false,
},
},
}
export default nextConfig/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
browserDebugInfoInTerminal: {
showSourceLocation: false,
},
},
}
module.exports = nextConfig| 版本 | 变更 |
|---|---|
v15.4.0 | 引入了 experimental browserDebugInfoInTerminal |