【问题标题】:Create New React Native app创建新的 React Native 应用程序
【发布时间】:2019-02-01 04:04:52
【问题描述】:

我在创建我的第一个 react 本机应用程序时遇到错误。 我正在使用以下指南 - https://facebook.github.io/react-native/docs/getting-started.html

https://github.com/react-community/create-react-native-app

$ npm install -g create-react-native-app
--Worked fine
$ create-react-native-app my-first-native-app
--app created without errors
$ npm start
--gives error

Error: React native is not installed. Please run `npm install` in your project directory.
1:09:05: Error starting packager: Error: Couldn't start project. Please fix the errors and restart the project.
    at C:\xdl\src\Project.js:1329:11
    at Generator.next (<anonymous>)
    at step (C:\reactJs-projects\my-first-native-app\node_modules\xdl\build\Project.js:1735:191)
    at C:\reactJs-projects\my-first-native-app\node_modules\xdl\build\Project.js:1735:361
    at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-first-native-app@0.1.0 start: `react-native-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-first-native-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

尝试按照建议将 npm 降级到版本 4 进行修复,因为版本 5 存在错误。

npm i -g npm@4

我也尝试过最新的 npm,但都没有成功。

当我在我的项目目录上运行 npm install 时,而不是安装/更新我的包,它会给出以下错误

npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

我看到所有在 node_modules 中下载的依赖项

对我错过了什么有什么建议吗?

我还注意到,在创建应用程序时(使用 create-react-native-app my-first-native-app)它还在控制台中添加了以下错误

yarn install v0.21.3
[1/4] Resolving packages...
warning jest-expo > jest > jest-cli > istanbul-api > istanbul-lib-hook@1.2.1: 1.2.0 should have been a major version bump
[2/4] Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/react-native-web-maps/-/react-native-web-maps-
0.1.0.tgz: invalid tar file".
info If you think this is a bug, please open a bug report with the information provided in "C:\\reactJs-projects
\\MyNewNativeApp\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Failed to install

谢谢!

【问题讨论】:

  • 我尝试了@GosulsEz 解决方案,但没有奏效

标签: node.js reactjs react-native npm


【解决方案1】:

在尝试了不同的版本之后,我最终使用了 yarn,并且它在第一个实例上运行。如果有人遇到类似问题,那么我建议使用 Yarn 并继续前进。创建应用程序后,可以切换回 npm。这是一个非常常见的问题,对于许多开发人员来说,它适用于特定版本。

【讨论】:

    【解决方案2】:

    在创建项目之后

    $ create-react-native-app my-first-native-app
    

    你应该进入你的项目文件夹之后:

    $ cd my-first-native-app
    

    然后打开模拟器或连接到旅游设备并运行

    $ npm start
    

    $ react-native run-android
    

    注意你已经安装了 android-SDK 和 android-JDK 并且你的模拟器正在运行

    【讨论】:

      【解决方案3】:

      重新安装你的 NPM/YARN 并获取最新版本的 React Native 我也有这个问题

      【讨论】:

      • 在 npm 弹出之后运行 npm install 或 yarn install
      • 我在 node 和 npm 更新之后创建了一个新应用程序,所以它应该带来所有新的包,你能解释一下 npm 弹出以及它是如何解决问题的吗?
      • 它没有解决问题,但这是带有包的ios和android文件夹
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 2023-04-01
      • 2021-06-26
      相关资源
      最近更新 更多