Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize React Native project

Please note I have read the documentation and I'm referencing the point where the error happens as well as the steps I have taken. Please don't advice me to follow the instructions that I have already indicated I have followed.

After following the documentation of React Native to the best of my ability, I have been unable to get React Native to run. I have installed jdk, node, and Android Studio as instructed (using Chocolatey and links). The Android Emulator runs from Android Studio. I'm using npm version 6.1.0, node version 8.4.0, jdk 8, Android Studio 3.1.3. The error I get after react-native init AwesomeProject is SyntaxError: Unexpected token import. What did I do wrong? How can I fix this? Running react-native run-android also gives the same error.

To be clear, I'm in the proper directory. ANDROID_HOME is set to the proper sdk folder. There is a heading, Running your React Native application, and running the first command leaves me with the error, but I don't get an error before that point.

like image 514
haleonj Avatar asked Jul 05 '18 17:07

haleonj


2 Answers

  1. install npm
  2. install react native cli => npm install -g
    react-native-cli && npm install -g react-native (admin or sudo)
    1. react-native init MyProject
    2. cd Myproject
    3. react-native run-ios or run-android
like image 80
tetar Avatar answered Nov 07 '22 08:11

tetar


  1. Update node to the latest version.
  2. npm install -g react-native-cli.
  3. npx react-native init newProject.

Since you install react native globally you don't need to use npx packages anymore just try

react-native init newProject

like image 28
cmcodes Avatar answered Nov 07 '22 08:11

cmcodes