【问题标题】:React Native: Getting errors after structuring the project foldersReact Native:构建项目文件夹后出现错误
【发布时间】:2022-08-03 19:06:00
【问题描述】:

我将文件夹结构更改为这样的

现在我收到这些错误

Error: Requiring module \"node_modules/react-native-reanimated/src/Animated.js\", which threw an exception: Error: Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated\'s babel plugin?

and 

Invariant Violation: \"main\" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn\'t called.

我更改了 package.json main 和 app.json 入口点

 \"main\": \"./src/App.tsx\",

仍然收到错误。

    标签: react-native expo


    【解决方案1】:

    在这里!通过执行这些步骤解决。如果有人遇到这个问题,如果它适合你,你可以试试这个。

    Error: Requiring module "node_modules/react-native-reanimated/src/Animated.js", which threw an exception: Error: Reanimated 2 failed to create a worklet, maybe you forgot to add Reanimated's babel plugin?
    

    为此,我正在使用反应导航抽屉。所以我必须确定我是否安装了 react-native-gesture-handler react-native-reanimated

    expo install react-native-gesture-handler react-native-reanimated
    

    如果您使用抽屉导航器并收到此错误,我建议您阅读本文。

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

    并为他的错误:

    Invariant Violation: "main" has not been registered. This can happen if:
    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
    

    我通过在 package.json 和 app.json 中添加 app.tsx(或根组件)的路径解决了这个问题

    app.json -> "entryPoint": "./src/App.tsx",
    package.json -> "main": "./src/App.tsx",
    

    最后,注册根组件,如以下链接中所述

    https://docs.expo.dev/versions/latest/sdk/register-root-component/

    还是行不通?尝试运行此命令

    expo start --clear
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      相关资源
      最近更新 更多