ERROR Error: Reanimated 2 failed to create a worklet

报错

To reload the app press "r"
To open developer menu press "d"

 BUNDLE  ./index.js 

 ERROR  Error: Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated's babel plugin?, js engine: hermes
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
 ERROR  Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

解决办法

修改配置文件babel.config.js并增加plugins: ['react-native-reanimated/plugin'],
module.exports = {
presets: [‘module:metro-react-native-babel-preset’],
plugins: [‘react-native-reanimated/plugin’],
};

这里你如果运行项目会发现报错依旧。是缓存在作怪。

清缓存

  • yarn
yarn start --reset-cache
  • npx
npx react-native start --reset-cache

这里在重启运行项目,就不会有这个错了。

百思不得解

其实在我老的项目中也用到了react-native-reanimated,而且我并没有在配置文件babel.config.js中增加

plugins: [‘react-native-reanimated/plugin’],
但是项目是可以正常运行的。

新项目中就必须加上这个才能运行,我非常不理解。

我猜测会不会是因为我在老项目中使用了ant design这个组件了,而新项目中没有使用这个组件。目前我只能找出这个区别。

参考

https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/

https://stackoverflow.com/questions/67130651/reanimated-2-failed-to-create-a-worklet-maybe-you-forgot-to-add-reanimateds-ba

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值