繁体   English   中英

创建新的 React Native 应用程序

[英]Create New React Native app

我在创建我的第一个反应原生应用程序时遇到错误。 我正在使用以下指南 - 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

谢谢你!

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

创建你的项目后

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

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

$ cd my-first-native-app

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

$ npm start

或者

$ react-native run-android

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

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

使用命令创建新项目: npx react-native init ProjectName

使用特定版本的 react native 创建新项目: npx react-native init ProjectName --version X.XX.X

之后转到项目位置cd ProjectName

在 android 平台上运行应用程序npx react-native run-android

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM