haleonj
haleonj

Reputation: 1518

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.

Upvotes: 11

Views: 73714

Answers (5)

tetar
tetar

Reputation: 872

  1. install npm
  2. install react native cli => npm install -g
    react-native-cli && npm install -g react-native (admin or sudo)
  3. react-native init MyProject
  4. cd Myproject
  5. react-native run-ios or run-android

Upvotes: 22

sar lavi
sar lavi

Reputation: 81

Update Sep, 2024.

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:

npm uninstall -g react-native-cli @react-native-community/cli
npx @react-native-community/cli@latest init AwesomeProject

[Optional] Using a specific version or template

npx @react-native-community/[email protected] init AwesomeProject --version X.XX.X

Related Docs

Upvotes: 3

DASH BYTE
DASH BYTE

Reputation: 11

using this command you can select the template in react native setup

npx create-expo-app --template

Upvotes: 1

Ori
Ori

Reputation: 632

Assuming that you have Node 14 LTS or greater installed, you can use npm to install the Expo CLI command line utility:

npm install -g expo-cli

Then run the following commands to create a new React Native project called "AwesomeProject":

expo init AwesomeProject

cd AwesomeProject
npm start

Source: React Native Environment Setup

Upvotes: 0

cmcodes
cmcodes

Reputation: 1866

  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

Upvotes: 8

Related Questions