android - 错误: Requiring module "node_modules\react-native-reanimated\src\Animated.js"

标签 android node.js react-native expo babeljs

我正在 React Native Expo 中制作一个应用程序。它可以在网络浏览器上运行,但无法在我手机上的 Android 模拟器或 expo go 应用程序上运行。我收到 2 个错误:-

错误:需要模块“node_modules\react-native-reanimated\src\Animated.js”,抛出异常:错误:Reanimated 2 未能创建工作集,也许您忘记添加 Reanimated 的 babel 插件?

不变违规:“main”尚未注册。如果出现以下情况,就会发生这种情况:

  • Metro(本地开发服务器)从错误的文件夹运行。检查 Metro 是否正在运行,停止它并在当前项目中重新启动它。

如有任何帮助,我们将不胜感激

我的世博 SDK:44,

我的package.json

    {
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "~1.15.0",
    "@react-native-community/masked-view": "^0.1.10",
    "axios": "^0.24.0",
    "expo": "^44.0.0",
    "expo-status-bar": "~1.2.0",
    "ngrok": "^4.2.2",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-gesture-handler": "~2.1.0",
    "react-native-reanimated": "~2.3.1",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.10.1",
    "react-native-web": "0.17.1",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4",
    "react-navigation-tabs": "^2.11.0",
    "react-native-maps": "0.29.4"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

我的 babel.config

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: ["react-native-reanimated/plugin"],
  };
};

最佳答案

正如reanimated中提到的doc ,

  • 安装yarn添加react-native-reanimated@next
  • 编辑 babel 插件配置
module.exports = function (api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    plugins: ['react-native-reanimated/plugin'],
  };
};
  • 清除 Metro Bundler 缓存并启动 expo expo start --clear

这应该可以解决问题!

关于android - 错误: Requiring module "node_modules\react-native-reanimated\src\Animated.js",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70493915/

相关文章:

android:如何获取给定 TextView 的背景颜色的 ARGB 值

javascript - Mongoose.js : Find users, 然后检查用户的值

javascript - 在 native react 中传递另一个页面上的值

android - 未安装 Ionic firebase 手机身份验证插件

java - Android 在运行时无法从 JAR 中找到方法

android - 如何限制 ListView 中的复选框选择?

node.js - 单击后如何禁用 slackbot 按钮

node.js - 如何真正调试node.js应用程序?

react-native - 是否需要使用StyleSheet.create?

react-native - React Native Pod安装错误: NoMethodError - undefined method `framework?' for nil:NilClass