facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.9k stars 24.3k forks source link

Failing run on IOS and Android because a syntax error in `local-cli` #20167

Closed verybluebot closed 6 years ago

verybluebot commented 6 years ago

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)
react-native-bot commented 6 years ago

It looks like your issue may be missing some necessary information. Can you run react-native info and edit your issue to include these results under the Environment section?

hichamalaoui05 commented 6 years ago

having the same issue react-native run-ios /Users/admin/workspace/aelamd/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. (/Users/admin/workspace/aelamd/node_modules/react-native/local-cli/cli.js:17:1)

verybluebot commented 6 years ago

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.

matt-am-i commented 6 years ago

I am having the same issue - even with an empty project created by using react-native init react-native info shows the following:

React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.5
      CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
      Memory: 558.48 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 9.10.0 - ~/.nvm/versions/node/v9.10.0/bin/node
      Yarn: 1.7.0 - /usr/local/bin/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v9.10.0/bin/npm
      Watchman: 4.9.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: 23.0.1, 25.0.2, 26.0.1, 26.0.2, 27.0.3
        API Levels: 23, 26, 27
    IDEs:
      Android Studio: 3.1 AI-173.4720617
      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:
      react-native-cli: 2.0.1
meehanman commented 6 years ago

Me too... Looks like something @TheSavior could fix.

mrmorais commented 6 years ago

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.

verybluebot commented 6 years ago

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 .

elicwhite commented 6 years ago

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.

verybluebot commented 6 years ago

Ok @TheSavior Ill try to play around with that and let you know, please keep this issue open for now so it will help others

verybluebot commented 6 years ago

@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

patrickkempff commented 6 years ago

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

verybluebot commented 6 years ago

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)
patrickkempff commented 6 years ago

@verybluebot your nvm output looks normal. Maybe you can try to temporary uninstall v6.10.3 and try again running the package again.

I think this is a coincidence but the version in message (You are currently running io.js v6.10.3) matches a version returned from nvm list. Altough the message is about io.js and nvm is pointing to node.

cristianonescu commented 6 years ago

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

rwichmann commented 6 years ago

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.

verybluebot commented 6 years ago

@rwichmann yes the solution is to remove all older node versions. But this is only a walkaround as (in my case) I have other projects that I need to use older version of node with them so for me the only solution for now is to use a downgraded (0.55.3 as said above) of React Native. Hope React Native team could implement a better fix for this

rwichmann commented 6 years ago

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.

anupamsmaurya commented 6 years ago

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.

kdenz commented 6 years ago

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.

elicwhite commented 6 years ago

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

tzilist commented 6 years ago

We are using Microsoft Appcenter to do our CI and have no control over the version of Node they use. Would it be possible to just remove the dangling comma?

dancham86 commented 6 years ago

@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 "/"
tzilist commented 6 years ago

@dancham86 That works! Thank you!

LiuYanpin commented 6 years ago

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.

robhogan commented 6 years ago

@TheSavior is there any point at all to the checkNodeVersion script if it doesn't execute on any version for which it would generate its output? The whole point of it is to verify node > 8 with a helpful message. At least that script has to work on node < 8!

elicwhite commented 6 years ago

That is a valid point. :-)

I’d accept a PR that adds @noformat to the top of the file, eslint disables at the top of the file for whatever rules we enforce that aren’t compatible and a removal of the trailing commas and such.

niall-m commented 6 years ago

Having the same issue. I've tried every tactic suggested here, but I can't seem to get it working...

After entering 'nvm install stable' or 'nvm alias default v10.9.0' on the CL, Node keeps reverting to v6.10.1 when I restart the terminal. Also tried the "sudo npm cache clean" command listed above to no avail.

When I entered 'nvm install node && nvm alias default node', node -v outputs v10.9.0, but then tried react-native run-ios (without restarting terminal), which outputs "Scanning folders for symlinks... iOS project folder not found. Are you sure this is a React Native project?"

Not sure what the problem is or what to try next. I also have projects running on older versions of node in the same parent directory, so didn't want to delete v6. Any advice much appreciated.

robhogan commented 6 years ago

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.

nicollecastrog commented 6 years ago

thanks @rh389!! 😄your comment along with this SO issue did the trick!

nicollecastrog commented 6 years ago

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
timxor commented 6 years ago

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~

balgovindy commented 5 years ago

Yes, this is problem with node version.

BalaRajendran commented 5 years ago

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

Its working for me also ,,Thanking You

kiorq commented 5 years ago

Setting the default alias to 8 works fine for me, but I would prefer specifying in the config, which i've had no luck doing.

kuzyakiev commented 5 years ago

Maybe someone has the same problem. So, all works fine until I install: https://www.iterm2.com/index.html and https://github.com/robbyrussell/oh-my-zsh Fix was as @nicollecastrog mention before, fix was copy NVM init lines from ~/.profile to ~/.zshrc

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

or just add in ~/.zshrc

source ~/.profile