19

I am creating a new react-native project using :

react-native init {proj_name}

But I am getting the following error.

D:\Reactnative\Project\{proj_name}\node_modules\react-native\local-cli\cliEntry.js:30
import type {CommandT} from './commands';
^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Module._compile (D:\Reactnative\Project\Learnwizz\node_modules\pirates\lib\index.js:91:24)
    at Module._extensions..js (module.js:654:10)
    at Object.newLoader [as .js] (D:\Reactnative\Project\Learnwizz\node_modules\pirates\lib\index.js:96:7)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Module.require (module.js:587:17)
Matsemann
  • 21,083
  • 19
  • 56
  • 89
Mayank Raj
  • 921
  • 2
  • 12
  • 23

5 Answers5

25

This is a known bug right now with react-native 0.56 when running on Windows (see here and here).

Until it is fixed, you can work around the issue by explicitly specifying an older version of react-native when running react-native init. E.g.

react-native init {proj_name} --version react-native@0.55.4

Auth Infant
  • 1,760
  • 1
  • 16
  • 34
  • How to use run-android command with this? I'm trying react-native run android --version react-native@0.55.4, unsuccessfully. – Jhonatan Pereira Jul 05 '18 at 22:50
  • @JhonatanPereira - I don't think you have to specify react-native version when using react-native run-android. It should only be used when you are creating the project using react-native init. – Hylle Jul 06 '18 at 00:23
  • Understood, but I'm seeing the error yet... In an existing project, while I'm trying run application :( – Jhonatan Pereira Jul 06 '18 at 00:34
4

EDIT: As a temporary workaround, you can init your project with the previous version of RN using react-native init --version="0.55.4" {projectName}

I'm also running into this exact error today. I just now noticed react-native init is now using react-native 0.56 which was just release a few hours ago I believe.

This might give you some troubleshooting ideas.

1

Currently I am getting Exception in latest version that is 0.56 (React Native) and not able to run the code in emulator, However I have downgraded React native version to 0.55.4, then it is working for me..

Run Below line of command :

react-native init {project_name} --version react-native@0.55.4
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
sumit kumar pradhan
  • 614
  • 1
  • 6
  • 12
0

Yes, with new version of react-native , typescript code in react-cli has some issue , but don't worry go to app folder hit command

npm uninstall react-native --save
npm install react-native@0.55.4 --save

will solve your problem !!

0

in windows 10 update node.js to version 14.18.1

https://nodejs.org/dist/v14.18.1/node-v14.18.1-x64.msi

Iman Roosta
  • 2,228
  • 12
  • 13