panicThreshold 选项控制 React 编译器在编译期间如何处理错误。
🌐 The panicThreshold option controls how the React Compiler handles errors during compilation.
{
panicThreshold: 'none' // Recommended
}参考
🌐 Reference
panicThreshold
确定编译错误是否应该导致构建失败或跳过优化。
🌐 Determines whether compilation errors should fail the build or skip optimization.
类型
🌐 Type
'none' | 'critical_errors' | 'all_errors'默认值
🌐 Default value
'none'
选项
🌐 Options
'none'(默认,推荐):跳过无法编译的组件并继续构建'critical_errors':仅在出现严重编译器错误时使构建失败'all_errors':在任何编译器诊断时使构建失败
注意事项
🌐 Caveats
- 生产环境构建应始终使用
'none' - 构建失败会导致应用无法构建
- 编译器会自动检测并跳过带有
'none'的有问题代码 - 更高的阈值仅在开发调试阶段有用
用法
🌐 Usage
生产环境配置(推荐)
🌐 Production configuration (recommended)
对于生产构建,请始终使用 'none'。这是默认值:
🌐 For production builds, always use 'none'. This is the default value:
{
panicThreshold: 'none'
}这确保了:
🌐 This ensures:
- 你的构建不会因编译器问题而失败
- 无法优化的组件正常运行
- 最大化组件优化
- 稳定的生产部署
开发调试
🌐 Development debugging
暂时使用更严格的阈值来查找问题:
🌐 Temporarily use stricter thresholds to find issues:
const isDevelopment = process.env.NODE_ENV === 'development';
{
panicThreshold: isDevelopment ? 'critical_errors' : 'none',
logger: {
logEvent(filename, event) {
if (isDevelopment && event.kind === 'CompileError') {
// ...
}
}
}
}