react-native: Failing run on IOS and Android because a syntax error in `local-cli`
- Review the documentation: https://facebook.github.io/react-native
- Search for existing issues: https://github.com/facebook/react-native/issues
- Use the latest React Native release: https://github.com/facebook/react-native/releases
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)
Try running the following. For me it worked.
sudo npm cache clean -f && sudo npm install -g n install "n" && sudo n stableI 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
NOTE: this error is only with
React Native version 0.56.0, downgrading will solve this particular error but causes multiple other incompatibility issues. version0.55.3seems to be workingNOTE2: for some reason the bot flagged this issue with
No Environment Infoeven 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
nvmand a non-default shell (likezsh).nvmis 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 wherenodeis a modern version) might help the other shell to pick up nvm’s node in some cases. Otherwise you could tryecho $PATHandwhich nodein 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:
from the bundler, Im using nvm but pretty sure I have the right version selected.
node -vshows the right one. any ideas?NOTE: this is not a notification note as Im getting the error
no bundle URL presenton the deviceYes, 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
nvmsetup. Once I added these two lines to my~/.zshrc, then the right node version was loaded to myPATH, and new terminal windows loaded the right node version: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:
Just got mine working. Had to remove a nvm 6.x.x version.
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:
nvm.nvm uninstall 6.xetc.sudo npm cache clean -f && sudo npm install -g n install "n" && sudo n stablefrom @cristianonescureact-native run-iosI’m not sure if I really needed step 2, but Step 1 and Step 3 were necessary in my case.
sure
@verybluebot can you report the result of
nvm listhere?