runtime-debug
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRuntime Debug
运行时调试
Use this skill when reproducing runtime-bundle, module-resolution, or user-bundle inclusion regressions.
当复现运行时包、模块解析或用户包引入的回归问题时,可使用本技能。
Local Repro Discipline
本地复现规范
- Mirror CI env vars when reproducing CI failures.
- Key variables: forces webpack (turbopack is default),
IS_WEBPACK_TEST=1skips packing next.js.NEXT_SKIP_ISOLATE=1 - For module-resolution validation, always rerun without .
NEXT_SKIP_ISOLATE=1
- 复现CI失败问题时,镜像CI环境变量。
- 关键变量:强制使用webpack(默认是turbopack),
IS_WEBPACK_TEST=1跳过Next.js的打包步骤。NEXT_SKIP_ISOLATE=1 - 进行模块解析验证时,务必在不设置的情况下重新运行。
NEXT_SKIP_ISOLATE=1
Stack Trace Visibility
堆栈追踪可见性
Set to disable the ignore-list filtering in dev server error output. By default, Next.js collapses internal frames to , which hides useful context when debugging framework internals. Defined in .
__NEXT_SHOW_IGNORE_LISTED=trueat ignore-listed framespackages/next/src/server/patch-error-inspect.ts设置可禁用开发服务器错误输出中的忽略列表过滤功能。默认情况下,Next.js会将内部调用栈折叠为,这会在调试框架内部逻辑时隐藏有用的上下文信息。该配置定义于文件中。
__NEXT_SHOW_IGNORE_LISTED=trueat ignore-listed framespackages/next/src/server/patch-error-inspect.tsUser-Bundle Regression Guardrail
用户包回归防护措施
When user starts bundling internal Node-only helpers unexpectedly:
next build- Inspect route trace artifacts ().
.next/server/.../page.js.nft.json - Inspect traced server chunks for forbidden internals (e.g. ,
next/dist/server/stream-utils/node-stream-helpers.js).node:stream/promises - Add a assertion that reads the route trace and traced server chunks, and fails on forbidden internals. This validates user-project bundling (not publish-time runtime bundling).
test-start-webpack
当用户执行时意外打包了仅适用于Node.js的内部辅助工具时:
next build- 检查路由追踪产物()。
.next/server/.../page.js.nft.json - 检查已追踪的服务器代码块,确认是否包含禁用的内部模块(例如、
next/dist/server/stream-utils/node-stream-helpers.js)。node:stream/promises - 添加一个断言,读取路由追踪信息和已追踪的服务器代码块,若检测到禁用的内部模块则触发失败。此操作可验证用户项目的打包情况(而非发布时的运行时打包)。
test-start-webpack
Bundle Tracing / Inclusion Proof
包追踪 / 引入验证
To prove what user bundling includes, emit webpack stats from the app's :
next.config.jsjs
// next.config.js
module.exports = {
webpack(config) {
config.profile = true
return config
},
}Then use and diff between modes. This gives concrete inclusion reasons (e.g. which module required ) and is more reliable than analyzer HTML alone.
stats.toJson({ modules: true, chunks: true, reasons: true })webpack-stats-server.jsonnode:stream/promises若要验证用户打包包含的内容,可从应用的中输出webpack统计信息:
next.config.jsjs
// next.config.js
module.exports = {
webpack(config) {
config.profile = true
return config
},
}随后使用,并对比不同模式下的文件。这将提供具体的模块引入原因(例如哪个模块依赖了),比仅使用分析器HTML报告更可靠。
stats.toJson({ modules: true, chunks: true, reasons: true })webpack-stats-server.jsonnode:stream/promisesRelated Skills
相关技能
- - flag wiring (config/schema/define-env/runtime env)
$flags - - DCE-safe require patterns and edge constraints
$dce-edge - - entry-base boundaries and vendored React
$react-vendoring
- - 标志配置(config/schema/define-env/runtime env)
$flags - - 支持DCE的引入模式及边缘环境约束
$dce-edge - - 入口基础边界与预打包React
$react-vendoring