在创建我的第一个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.
在整个版本5上,建议将npm降级至版本4进行修复。
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
谢谢!
答案 0 :(得分:1)
重新安装您的NPM / YARN并获得最新版本的React Native,我也遇到这个问题
答案 1 :(得分:1)
使用创建项目后
Target framework
输入项目文件夹后:
$ create-react-native-app my-first-native-app
然后打开模拟器或连接到游览设备并运行
$ cd my-first-native-app
或
$ npm start
请注意,您已经安装了android-SDK和android-JDK,并且模拟器正在运行
答案 2 :(得分:1)
在尝试了不同的版本之后,我最终使用yarn,并且它在一开始就可以工作。如果有人遇到类似问题,那么我建议您使用Yarn并继续前进。创建应用后,可以切换回npm。这是非常常见的问题,对于许多开发人员来说,它可以与某些版本一起使用。