xcode 使用错误的 node.js 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34035421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xcode using wrong node.js version
提问by Allan Jiang
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:
我是 React Native 的新手。我曾经react-native init XXX
创建一个新项目。启动 xcodeproj 时,我收到一条错误消息:
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+.
根据我的研究,这是一个 node.js 版本问题:我应该使用 v.4.0+。
I am using NVM to manage my node.js versions. In regular terminal window, I have this:
我正在使用 NVM 来管理我的 node.js 版本。在常规终端窗口中,我有这个:
$ 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..
但是在 xcode 中,当它运行启动 shell 脚本时,我看到它使用了不同的版本v0.10.40
,并且 xcode 也不知道nvm
命令......
The question is, how should I configure my Mac so the xcode can pick up the same version that I set with nvm?
问题是,我应该如何配置我的 Mac 以便 xcode 可以选择我使用 nvm 设置的相同版本?
Thank you!
谢谢!
Update: I tried to source
my ~/.bash_profile
in the shell script executed by xcode, but still not solving the problem.
更新:我尝试在 xcode 执行的 shell 脚本中执行source
我~/.bash_profile
的操作,但仍然没有解决问题。
采纳答案by Allan Jiang
I resolved the issue by adding . ~\.bash_profile
to the top of shell script.
我通过添加. ~\.bash_profile
到 shell 脚本的顶部解决了这个问题。
回答by Cihan Bebek
The problem seems to occur when you have installed react-native-cli with the wrong Node (and thus npm) version.
当您使用错误的 Node(以及 npm)版本安装 react-native-cli 时,似乎会出现此问题。
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:
首先关闭 xcode,让我们确保没有旧的节点进程在运行,我不确定这是否有必要,但最好确保:
$ 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 节点版本设置为您要使用的版本,例如:
$ 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):
现在重新安装 react-native-cli 并激活新的节点版本(它会影响 npm 版本):
$ 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).
现在运行$ react-native run-ios
应该使用正确的版本运行 xcode!(如果没有,请确保重新启动终端/xcode 并重试)。
回答by Can Gülse
回答by pingo
I resolved by adding . ~/.nvm/nvm.sh
to the top of the shell script in Build Phases
我通过. ~/.nvm/nvm.sh
在 Build Phases 中添加到 shell 脚本的顶部来解决
回答by scaly
For me, adding this to /etc/profile
or to ~/.profile
worked:
对我来说,将此添加到/etc/profile
或~/.profile
工作:
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"
The reason this is necessary is because XCode uses /bin/sh
by default and it loads the profiles from the files I specified.
这是必要的原因是因为 XCode/bin/sh
默认使用并且它从我指定的文件中加载配置文件。
Note: altering /etc/profile
requires you to use sudo
. Not sure if this is even possible on MacOS X 10.15 Catalina since I believe they made the system directories to be read-only, no matter what. But if you are able to set it here, this will make it work for any user who has nvm installed.
注意:更改/etc/profile
需要您使用sudo
. 不确定这在 MacOS X 10.15 Catalina 上是否可行,因为我相信他们将系统目录设为只读,无论如何。但是如果你能在这里设置它,这将使它适用于任何安装了 nvm 的用户。
回答by Ciriac
Seeing as this is the top result in Google while searching for this error, the following is the only thing that worked for me.
看到这是搜索此错误时 Google 中的最佳结果,以下是唯一对我有用的方法。
I had to uninstall node (that was previously installed with the pkg from the Node website), uninstall nvm and reinstall node with Brew.
我必须卸载节点(之前从 Node 网站使用 pkg 安装),卸载 nvm 并使用 Brew 重新安装节点。
Linkfor more information.
链接以获取更多信息。