简体   繁体   中英

Create New React Native app

I am getting an error on creating my first react native app. I am using following guide - 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.

Tried fixing with downgrading npm to version 4 as recommended all over that version 5 has bugs.

npm i -g npm@4

I have also tried latest npm but neither of them worked.

When I run npm install on my project directory, instead of installing/updating my packages, it is giving following error

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>

I see all dependencies downloaded in node_modules though

Any suggestion on what I have missed?

What I also noticed is when the app is created (using create-react-native-app my-first-native-app) it also added following error in console

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

Thank You!

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

after create your project with

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

after you should enter your project folder :

$ cd my-first-native-app

and then open emulator or connect to tour device and run with

$ npm start

or

$ react-native run-android

pay attention you had installed android-SDK and android-JDK and your emulator is running

After trying different versions, I ended up using yarn and it worked on first instance. If anyone struggles with similar problem, then I would recommend using Yarn and move on. One can switch back to npm after the app is created. This is very common issue reported and for many developers it works with certain version.

Create new project using command : npx react-native init ProjectName

Create new project using particular version of react native : npx react-native init ProjectName --version X.XX.X

After that go to project location cd ProjectName

Run application on android platform npx react-native run-android

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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