react-native: React native 0.56.* - "Unexpected identifier"

Environment

Run react-native info in your terminal and paste its contents here.

C:\Projects\AwesomeProject>react-native info
C:\Projects\AwesomeProject\node_modules\react-native\local-cli\cliEntry.js:30
import type {CommandT} from './commands';
       ^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:670:28)
    at Module._compile (C:\Projects\AwesomeProject\node_modules\pirates\lib\index.js:91:24)
    at Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Object.newLoader [as .js] (C:\Projects\AwesomeProject\node_modules\pirates\lib\index.js:96:7)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)

So manually:

  • Windows 10.1803.17134.112 x64
  • Node 10.5.0
  • Npm 6.1.0

[skip envinfo]

Description

Any attempt at react-native start or any other react-native cli feature - results in:

C:\Projects\AwesomeProject>react-native info
C:\Projects\AwesomeProject\node_modules\react-native\local-cli\cliEntry.js:30
import type {CommandT} from './commands';
       ^^^^

SyntaxError: Unexpected identifier

Reproducible Demo

  • create-react-native-app
  • npm run eject
  • react-native-git-upgrade next
  • Need to add "babel-preset-react-native": "^5.0.1" to package.json according to the CHANGELOG.
  • Add "babel-preset-react-native" preset to .babelrc
  • npm i
  • react-native start

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 59 (12 by maintainers)

Most upvoted comments

Here the same problem !!!

import type {CommandT} from './commands';

       ^^^^

SyntaxError: Unexpected identifier
    at new Script (vm.js:74:7)
    at createScript (vm.js:246:10)
    at Object.runInThisContext (vm.js:298:10)
    at Module._compile (internal/modules/cjs/loader.js:670:28)

if you need to create a project you can use the latest stable version directly, it worked for me!

react-native init --version="0.55.4" MyNewApp

For me it resolved the initial issue (so did hotfixing it myself from previous posts). but both solutions lead me to another issue, i cant realy tell if its related

Loading dependency graph, done.
error: bundling failed: Error: Unable to resolve module 'AccessibilityInfo' from
 'C:\Users\jm\Documents\Privat\ReactNative\Test056\node_modules\react-native\Lib
raries\react-native\react-native-implementation.js': Module 'AccessibilityInfo'
does not exist in the Haste module map

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: 'watchman watch-del-all'.
  2. Delete the 'node_modules' folder: 'rm -rf node_modules && npm install'.
  3. Reset Metro Bundler cache: 'rm -rf /tmp/metro-bundler-cache-*' or 'npm star
t -- --reset-cache'.  4. Remove haste cache: 'rm -rf /tmp/haste-map-react-native
-packager-*'.
    at ModuleResolver.resolveDependency (C:\Users\jm\Documents\Privat\ReactNativ
e\Test056\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:
167:1306)
    at ResolutionRequest.resolveDependency (C:\Users\jm\Documents\Privat\ReactNa
tive\Test056\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest
.js:80:16)
    at DependencyGraph.resolveDependency (C:\Users\jm\Documents\Privat\ReactNati
ve\Test056\node_modules\metro\src\node-haste\DependencyGraph.js:237:485)
    at Object.resolve (C:\Users\jm\Documents\Privat\ReactNative\Test056\node_mod
ules\metro\src\lib\transformHelpers.js:116:25)
    at dependencies.map.result (C:\Users\jm\Documents\Privat\ReactNative\Test056
\node_modules\metro\src\DeltaBundler\traverseDependencies.js:298:29)
    at Array.map (<anonymous>)
    at resolveDependencies (C:\Users\jm\Documents\Privat\ReactNative\Test056\nod
e_modules\metro\src\DeltaBundler\traverseDependencies.js:294:16)
    at C:\Users\jm\Documents\Privat\ReactNative\Test056\node_modules\metro\src\D
eltaBundler\traverseDependencies.js:159:33
    at Generator.next (<anonymous>)
    at step (C:\Users\jm\Documents\Privat\ReactNative\Test056\node_modules\metro
\src\DeltaBundler\traverseDependencies.js:239:307)

React Native Environment Info: System: OS: Windows 7 CPU: x64 Intel® Core™ i5-5200U CPU @ 2.20GHz Memory: 3.20 GB / 11.92 GB Binaries: Yarn: 1.7.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.1.0 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 1.5.0.0 AI-141.2456560

node -v v9.10.1

this is done from a clean react-native init Test056 react-native run-android

This issue was already reported multiple times in early rc stages of 0.56 (i guess it was even 0.56-rc.0). Did my best to investigate and resolve this issue, but really hadn’t enough time to fix metro etc.

To cite myself from 20 days ago:

Might be a react-native issue, might be a metro issue or might be a babel issue. Anyways, v0.56.0-rc is broken on windows.

So, the react-native core team is aware of this issue and knew that react-native 0.56 is broken on windows when they decided to make the 0.56.0 release, but they wanted to go fast with this release. So, just keep calm and hope the best for 0.56.1.

------------Final Solution------------ We can’t use RN0.56. To run your code, you should downgrade RN to 0.55.4. No way else!!!

ok, this is pretty serious. I think it’s time to warn the big guys to inspect on this (hope I’ll do nothing wrong) @brentvatne

@danielgindi The “rc” from the title can be removed, this problem affects also the current 0.56 released today

Hello everyone! A new release of metro, 0.38.2, has been released and it should fix this issue. Since RN 0.56.0 depends on metro version

    "metro": "^0.38.1",
    "metro-babel-register": "^0.38.1",
    "metro-core": "^0.38.1",
    "metro-memory-fs": "^0.38.1",

This means that to apply the fix you would simply need to remove the node_modules (and if they’re using yarn.lock you’ll need to also clean metro from the lock file) and reinstall.

I’ll unlock the issue in order to get some feedback that this new release of metro actually fixes for you all, since there is always the scenario in which we haven’t covered every possible Win configuration during our tests.

@johakr I’m just surprised a release took place with a whole platform being broken. Without a FAT warning in the release notes or potentially even the CLI client on breakage, this means that you impose wasted time on every developer who happens to be working on a Windows machine, which quickly amounts to thousands of hours evaporating into thin air. Hence the surprise. Apart from that, all good (and calm 😉 on my side, I’ll just keep sitting on the stable 0.55.x version 😃

@DanielEncina react-native init --version="0.55.4" MyNewApp it works, thank you !

Same problem here. It started when I deleted my node_modules folder and run npm install.

EDIT: I fixed it opening my package.json and change the react-native version from 0.56.0 to 0.55.4, then I execute npm install again and it worked.

I think it’s a Windows specific problem, I’m running into the same issue.

It’s been reported here: https://github.com/facebook/react-native/issues/19669 https://github.com/facebook/react-native/issues/19654

And there’s a pull request pending here: https://github.com/gengjiawen/react-native/tree/feature/RNTester_start

Unfortunately, I could not get that to work either on my end.

Anyone had success beating this problem?