I am new to React Native. I used react-native init XXX
to create a new project. When launch the xcodeproj, I got an error saying:
const setupEnvScript = /^win/.test(process.platform)
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Module._extensions..js (module.js:474:10)
at Object.require.extensions.(anonymous function) [as .js] (/Users/allanhahaha/Documents/Seat/getseat/SeatApp/node_modules/react-native/node_modules/babel-core/lib/api/register/node.js:214:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/allanhahaha/Documents/Seat/getseat/SeatApp/node_modules/react-native/cli.js:15:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
According to my research, this is a node.js version issue: I should have use v.4.0+.
I am using NVM to manage my node.js versions. In regular terminal window, I have this:
$ node --version
v5.1.0
but in xcode when it run the start shell script, I saw it is using a different version, v0.10.40
, and xcode doesn't know about nvm
command either..
The question is, how should I configure my Mac so the xcode can pick up the same version that I set with nvm?
Thank you!
Update: I tried to source
my ~/.bash_profile
in the shell script executed by xcode, but still not solving the problem.
The problem seems to occur when you have installed react-native-cli with the wrong Node (and thus npm) version.
First shut down xcode and let's make sure that there is no old node processes running, I'm not sure if this is necessary but it is good to make sure:
$ ps -e|grep node
$ kill {process number(s) here}
Then set the default nvm node version to the one you want to use, for example:
$ nvm alias default 6.6.0
Then restart your terminal and make sure that the node version is now the one you want by default:
$ node -v
v6.6.0
Now reinstall react-native-cli with the new node version active (it affects the npm version):
$ npm install -g react-native-cli
Now running $ react-native run-ios
should run xcode with the proper version! (If it doesn't, make sure to restart your terminal/xcode and try again).
I resolved the issue by adding . ~\.bash_profile
to the top of shell script.
Add your node path to Build Phases / Bundle React Native Code and images settings
Seeing as this is the top result in Google while searching for this error, the following is the only thing that worked for me.
I had to uninstall node (that was previously installed with the pkg from the Node website), uninstall nvm and reinstall node with Brew.
Link for more information.
I resolved by adding . ~/.nvm/nvm.sh
to the top of the shell script in Build Phases
来源:https://stackoverflow.com/questions/34035421/xcode-using-wrong-node-js-version