【问题标题】:Getting Error: "React Native is not installed"出现错误:“未安装 React Native”
【发布时间】:2020-11-22 16:03:25
【问题描述】:

enter image description here

当我要执行命令 expo start 时,给我以下错误,我开始使用 react native 并且我没有管理太多,会是什么?

app.json

   

 {
  "expo": {
    "name": "Project",
    "slug": "Project",
    "version": "1.0.0",
    "orientation": "portrait",
    "sdkVersion": "35.0.0",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
}

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": {
    "expo": "^35.0.0",
    "react": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
    "expo-status-bar": "^1.0.2",
    "react-dom": "~16.11.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "~8.1.0"
  },
  "private": true
}

新错误

enter image description here

文件夹

我更改了文件夹中的文件

\node_modules\metro-config\src\defaults\blacklist.js

var sharedBlacklist = [
  /node_modules[/\\]react[/\\]dist[/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

现在这个错误出现了

通过直接在模拟器上安装 expo 解决了最后一个错误。

【问题讨论】:

    标签: react-native expo


    【解决方案1】:

    如错误所示,React Native 未安装。所以,

    (1)npm install

    (2)npm start

    就是这样。如果您仍然遇到任何问题,请通过包含您的 app.json 文件内容来更新您的问题。

    更新:

    我认为问题出在您的sdk 版本上。请尝试更改sdk的版本。

    (1) 将您的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": {
        "expo": "~37.0.3",
        "expo-status-bar": "^1.0.2",
        "react": "~16.11.0",
        "react-dom": "~16.11.0",
        "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
        "react-native-web": "~0.11.7"
      },
      "devDependencies": {
        "@babel/core": "^7.8.6",
        "babel-preset-expo": "~8.1.0"
      },
      "private": true
    }
    

    以上,我已将sdk 版本从38 更改为37

    (2) 删除 node_module.expo 文件夹(如果它们已在您的项目根目录中创建)。

    (3)npm install

    (4)npm start

    就是这样。它现在应该可以工作了!

    【讨论】:

    • 您能否将您的package.json 内容添加到您的问题中?
    • 我可以编辑帖子,抱歉耽搁了,我还是不知道如何使用这个网站。
    • 没关系。不用担心。我已经更新了我的答案。请尝试并告诉我。
    • 您必须更改 package.json 中的 react-native 并删除 URL 并放置特定版本,这是因为显然从 github 下载包需要很长时间,这就是为什么当您运行该命令未安装。
    • 您是否误删了app.json 文件?请检查它是否存在。
    【解决方案2】:

    尝试通过更改此行来更改 package.json 中 react-native 的来源:

    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
    

    为此

    "react-native": "^0.63.0",
    

    【讨论】:

    • 嗨,我试过了,但我继续错误,我用新的错误更新了帖子。
    猜你喜欢
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 2021-02-09
    • 1970-01-01
    • 2019-01-25
    相关资源
    最近更新 更多