“Unexpected token import” as error when creating new react-native project

  • A+

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) 


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


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: