panicThreshold

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'(默认,推荐):跳过无法编译的组件并继续构建

    ¥**'none'** (default, recommended): Skip components that can’t be compiled and continue building

  • 'critical_errors':仅在出现严重编译器错误时导致构建失败

    ¥**'critical_errors'**: Fail the build only on critical compiler errors

  • 'all_errors':任何编译器诊断导致构建失败

    ¥**'all_errors'**: Fail the build on any compiler diagnostic

注意事项

¥Caveats

  • 生产构建应始终使用 'none'

    ¥Production builds should always use 'none'

  • 构建失败会导致应用无法构建

    ¥Build failures prevent your application from building

  • 编译器会自动检测并跳过使用 'none' 的问题代码。

    ¥The compiler automatically detects and skips problematic code with 'none'

  • 更高的阈值仅在开发调试阶段有用

    ¥Higher thresholds are only useful during development for debugging


用法

¥Usage

生产环境配置(推荐)

¥Production configuration (recommended)

对于生产构建,请始终使用 'none'。这是默认值:

¥For production builds, always use 'none'. This is the default value:

{
panicThreshold: 'none'
}

这确保了:

¥This ensures:

  • 你的构建不会因编译器问题而失败

    ¥Your build never fails due to compiler issues

  • 无法优化的组件正常运行

    ¥Components that can’t be optimized run normally

  • 最大化组件优化

    ¥Maximum components get optimized

  • 稳定的生产部署

    ¥Stable production deployments

开发调试

¥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') {
// ...
}
}
}
}