You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native升级0.72.15至0.75.0遇.comments无效Plugin属性问题

解决React Native升级后“.comments is not a valid Plugin property”错误

这个错误并非来自你提供的index.js代码,根源在于Babel配置或依赖版本不兼容,以下是具体修复步骤:

  • 检查Babel配置文件(babel.config.js或.babelrc)
    查找所有插件配置中带有.comments的字段,新版Babel已移除该属性,直接删除即可。比如原配置若为:

    plugins: [
      ['@babel/plugin-transform-react-jsx', { comments: false }]
    ]
    

    修改为:

    plugins: [
      '@babel/plugin-transform-react-jsx'
    ]
    
  • 清理全量缓存

    1. 清理RN项目缓存:
      npx react-native start --reset-cache
      
    2. 清理iOS端缓存:
      • 关闭Xcode,删除~/Library/Developer/Xcode/DerivedData目录下所有内容
      • 项目目录下执行:
        pod deintegrate && pod install
        
  • 校验依赖兼容性

    1. 确认@react-native-firebase/messaging版本适配RN 0.75.0,必要时升级到对应兼容版本
    2. 核对@babel/core、@babel/preset-env等Babel相关依赖版本,确保与RN 0.75.0官方要求一致

你的index.js代码示例如下(本身无问题):

/**
 * @format
 */

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import messaging from '@react-native-firebase/messaging';

messaging().setBackgroundMessageHandler(async remoteMessage => {
    console.log('Message handled in the background!', remoteMessage);
});

AppRegistry.registerComponent(appName, () => App);

内容的提问来源于stack exchange,提问作者Prabhakaran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 04:41:01