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' ]清理全量缓存
- 清理RN项目缓存:
npx react-native start --reset-cache - 清理iOS端缓存:
- 关闭Xcode,删除
~/Library/Developer/Xcode/DerivedData目录下所有内容 - 项目目录下执行:
pod deintegrate && pod install
- 关闭Xcode,删除
- 清理RN项目缓存:
校验依赖兼容性
- 确认
@react-native-firebase/messaging版本适配RN 0.75.0,必要时升级到对应兼容版本 - 核对
@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
相关产品推荐
相关产品推荐

