react-native: Failing run on IOS and Android because a syntax error in `local-cli`

Environment

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

    System:
      OS: macOS High Sierra 10.13.5
      CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
      Memory: 1.24 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.5.0 - ~/.nvm/versions/node/v10.5.0/bin/node
      Yarn: 1.7.0 - /usr/local/bin/yarn
      npm: 6.1.0 - ~/.nvm/versions/node/v10.5.0/bin/npm
      Watchman: 4.7.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
      Android SDK:
        Build Tools: 21.1.2, 23.0.1, 24.0.1, 24.0.2, 25.0.0, 25.0.2, 26.0.0, 26.0.1, 26.0.2, 27.0.3
        API Levels: 21, 23, 24, 25, 26, 27
    IDEs:
      Android Studio: 3.0 AI-171.4443003
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.4.1 => 16.4.1 
      react-native: 0.56.0 => 0.56.0 
    npmGlobalPackages:
      create-react-native-app: 1.0.0
      react-native-cli: 2.0.1

Description

getting what seems to be a syntax error but mite be incompatible versions?

Reproducible Demo

creating new app with react-native init someAppName running react-native run-ios or react-native run-android getting a syntax error:

/Users/joe/someAppName/node_modules/react-native/local-cli/server/checkNodeVersion.js:43
    );
    ^
SyntaxError: Unexpected token )
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/joe/someAppName/node_modules/react-native/local-cli/cli.js:17:1)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 17
  • Comments: 35 (7 by maintainers)

Most upvoted comments

Try running the following. For me it worked. sudo npm cache clean -f && sudo npm install -g n install "n" && sudo n stable

I was facing the same problem. I also had old version(v6.9.2) but using v9.11.2 also giving this issue. I executed ‘nvm alias default 9’ and then restarted the terminal. It solved the issue. I did not have to uninstall old version of node because some other projects use that version. I hope it helps someone.

@tzilist You can use a script to change it, I believe:

appcenter-post-clone.sh

#!/usr/bin/env bash

set -ex
brew uninstall node@6
NODE_VERSION="8.9.4"
curl "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}.pkg" > "$HOME/Downloads/node-installer.pkg"
sudo installer -store -pkg "$HOME/Downloads/node-installer.pkg" -target "/"

NOTE: this error is only with React Native version 0.56.0, downgrading will solve this particular error but causes multiple other incompatibility issues. version 0.55.3 seems to be working

NOTE2: for some reason the bot flagged this issue with No Environment Info even though its there.

If you’re on a mac and you’re relying on Xcode to launch the packager / invoke node you’ll need to be wary of the node version used by whatever shell Xcode uses, which may not be the one your normal terminal is using, especially if you’re using nvm and a non-default shell (like zsh). nvm is deliberately per-shell for everything it does, so what you do in your usual shell won’t necessarily influence the version available to Xcode.

ln -s $(which node) /usr/local/bin/node (run from a shell where node is a modern version) might help the other shell to pick up nvm’s node in some cases. Otherwise you could try echo $PATH and which node in an Xcode shell script build phase (then check the build logs) to provide some clues about where Xcode is looking.

Another option is to change the shell script build phases in your xcode project to use your preferred shell, but that isn’t very portable if you’re on a team.

@TheSavior I messed around with the code (basically removed the trailing comma on the line stated) a little bit and tried to run with node 10.6.0 but getting this:

 ────────────────────────────────────────────────────────────────────────────┐ 
 │  You are currently running io.js v6.10.3.                                  │ 
 │                                                                            │ 
 │  React Native runs on Node 8.0 or newer. There are several ways to         │ 
 │  upgrade Node.js depending on your preference.                             │ 
 │                                                                            │ 
 │  nvm:       nvm install node && nvm alias default node                     │ 
 │  Homebrew:  brew unlink iojs; brew install node                            │ 
 │  Installer: download the Mac .pkg from https://nodejs.org/                 │ 
 │                                                                            │ 
 │  About Node.js:   https://nodejs.org                                       │ 
 │  Follow along at: https://github.com/facebook/react-native/issues/19226    │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 
Process terminated. Press <enter> to close the window



from the bundler, Im using nvm but pretty sure I have the right version selected. node -v shows the right one. any ideas?

NOTE: this is not a notification note as Im getting the error no bundle URL present on the device

Yes, that’s still a workaround. And I don’t really understand why uninstalling node versions affects the currently installed version. I expected them to be independent and capsuled. Strange.

For anyone else who lands here because the terminal window launched by Xcode when you run the app is defaulting to the system’s node version. It turns out that rather than updating the shell script build phases, what was wrong was my nvm setup. Once I added these two lines to my ~/.zshrc, then the right node version was loaded to my PATH, and new terminal windows loaded the right node version:

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

I have the same problem. Now I solved it. I use ‘nvm install v9.0.0’ to install node v9.0.0. The nvm is a tool to manage different version of node.Then I use ‘nvm alias default v9.0.0’ to set my node version to 9. I have to use other node version in my other project.I don’t know why it worked, yet it does. Hope it helps.

The answer seems to be make sure you are using a version of node > 8.3. 😃

If you could do some experimentation around that line to see if you can resolve the syntax error with your version of node then that would be helpful.

Node > 8 supports trailing commas in function arguments so if you are actually running node 10, that is supported.

I’d appreciate if you could do some more digging for us.

see my comment above, I tested it on node 10.5.0 still failed… only way to fix for me was to downgrade React Native ( locally, not react-native-cli) to 0.55.3

other version s gave my al sorts of other issues

On Fri, Jul 13, 2018, 15:02 Maradona Morais notifications@github.com wrote:

I guess it depends on the Node version. The issue is on a console.log call at checkNodeVersion. It’s calling like:

console.log(message,);

(not necessary comma)

On Node 7.10.1 console this kind of command is invalid. Maybe if you update to a new Node version it will works fine.

Note: I didn’t updated mine (still 7.10.1), I’m only assuming that a new version of Node supports that extra comma on console.log.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/20167#issuecomment-404812911, or mute the thread https://github.com/notifications/unsubscribe-auth/AR4EE-kw2kkA5od7ODPuvIuaYhAesmhqks5uGIxugaJpZM4VMoiu .

Just got mine working. Had to remove a nvm 6.x.x version.

nvm list
nvm uninstall 6.11.2
nvm install 8.12.0
nvm use 8.12.0
nvm alias default 8.12.0
nvm current

Then clean and rebuild your xcode project. Boom! Good to go~

I was using node v6.10.0 and same error pops up, then I switched it over to v8.9.2 and it’s fine.

Ok, I had the same problem as described: SyntaxError: Unexpected token in checkNodeVersion.js:43 And a red Screen in the app, missing no bundle URL present.

What fixed my problem was:

  1. Install node version 10.6.0, remove all v6.x versions of node with nvm. nvm uninstall 6.x etc.
  2. Run sudo npm cache clean -f && sudo npm install -g n install "n" && sudo n stable from @cristianonescu
  3. Then quit the simulator
  4. run react-native run-ios

I’m not sure if I really needed step 2, but Step 1 and Step 3 were necessary in my case.

sure

        v6.10.3
        v10.5.0
->      v10.6.0
         system
default -> node (-> v10.6.0)
node -> stable (-> v10.6.0) (default)
stable -> 10.6 (-> v10.6.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.3 (-> N/A)
lts/carbon -> v8.11.3 (-> N/A)

@verybluebot can you report the result of nvm list here?