【问题标题】:Error: Requiring module "node_modules\react-native-reanimated\src\Animated.js"错误:需要模块“node_modules\react-native-reanimated\src\Animated.js”
【发布时间】:2022-01-26 07:49:34
【问题描述】:

我正在 react native expo 中制作应用程序。它在网络浏览器上运行,但无法在我的手机上的 android 模拟器或 expo go 应用程序上运行。我得到 2 个错误:-

Error: Requiring module "node_modules\react-native-reanimated\src\Animated.js",抛出异常:Error: Reanimated 2 failed to create a worklet,也许你忘了添加Reanimated的babel插件?

不变违规:“main”尚未注册。在以下情况下可能会发生这种情况:

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

任何帮助将不胜感激

我的 expo 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"],
  };
};

【问题讨论】:

    标签: android node.js react-native expo babeljs


    【解决方案1】:

    我之前也遇到过同样的错误,我做了两件事:

    1. 通过键入实际安装的 react-native-reanimated yarn add react-native-reanimated@next 在 cmd 中。
    2. 通过键入确保我的展览中的所有内容都是最新的 expo update 并按 y 以获取兼容版本的每个模块。

    【讨论】:

      【解决方案2】:
      1. 停止服务器
      2. 运行 expo r -c 清除缓存。

      【讨论】:

        【解决方案3】:

        reanimateddoc中提到的,

        • 安装yarn add 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 start --clear

        这应该可以解决问题!

        【讨论】:

        • 这就是解决方案。非常感谢!
        • 这对我有用,谢谢!
        猜你喜欢
        • 2022-10-14
        • 1970-01-01
        • 2022-11-17
        • 2021-12-12
        • 2021-12-25
        • 2017-09-29
        • 2020-05-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多