在我的 mac M1(在 rosetta 仿真上运行)中,我在安装 node-expat 包时收到以下错误。
santhosh.kulandaiyan@santhosh Backend % npm i node-expat
> node-expat@2.4.0 install /Users/santhosh.kulandaiyan/code/ps/euler-ps/Backend/node_modules/node-expat
> node-gyp rebuild
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlparse.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmltok.o
CC(target) Release/obj.target/expat/deps/libexpat/lib/xmlrole.o
LIBTOOL-STATIC Release/libexpat.a
env: python: No such file or directory
make: *** [Release/libexpat.a] Error 127
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:400:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Darwin 21.4.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/santhosh.kulandaiyan/code/ps/euler-ps/Backend/node_modules/node-expat
gyp ERR! node -v v14.17.6
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-expat@2.4.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-expat@2.4.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/santhosh.kulandaiyan/.npm/_logs/2022-05-12T11_57_35_997Z-debug.log
我的节点版本如下,python 3 确实可以作为环境变量使用,也可以在 PATH 中使用。
node --version
v14.17.6
npm --version
6.14.15
printenv | grep python
PYTHON=/usr/bin/python
python --version
Python 3.8.9
看起来 node-expat 并不直接依赖于 python https://www.npmjs.com/package/node-expat
我无法弄清楚为什么它抱怨找不到 python。 如果我查看详细的输出,那么最后几行只是抱怨 npm i node-expat 失败..
74 78 verbose stack Error: node-expat@2.4.0 install: `node-gyp rebuild`
3175 78 verbose stack Exit status 1
3176 78 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
3177 78 verbose stack at EventEmitter.emit (events.js:400:28)
3178 78 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
3179 78 verbose stack at ChildProcess.emit (events.js:400:28)
3180 78 verbose stack at maybeClose (internal/child_process.js:1055:16)
3181 78 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
3182 79 verbose pkgid node-expat@2.4.0
3183 80 verbose cwd /Users/santhosh.kulandaiyan/code/ps/euler-ps/Backend
3184 81 verbose Darwin 21.4.0
3185 82 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "i" "node-expat"
3186 83 verbose node v14.17.6
3187 84 verbose npm v6.14.15
3188 85 error code ELIFECYCLE
3189 86 error errno 1
3190 87 error node-expat@2.4.0 install: `node-gyp rebuild`
3191 87 error Exit status 1
3192 88 error Failed at the node-expat@2.4.0 install script.
3193 88 error This is probably not a problem with npm. There is likely additional logging output above.
3194 89 verbose exit [ 1, true ]
请提供任何帮助!
一旦我将其缩小到 node-gyp
特定问题,我就能够解决这个确切的问题。
node-gyp
自述文件包含适用于 Mac 的步骤。 This document has all the details,但被混淆地称为Installation notes for macOS Catalina (v10.15)
。那可能会让你失望。 The main readme 说的更正确:
如果您的 Mac 已升级到 macOS Catalina (10.15) 或更高版本,请阅读 macOS_Catalina.md。
我根据这些页面上的信息执行了以下操作以使其全部正常工作:
- 我确认我安装了兼容版本的 Python:
Python v3.7, v3.8, v3.9, or v3.10
- 我验证了
XCode Command Line Tools
已安装- 我安装了
node-gyp
npm install -g node-gyp
这会给你安装node-gyp
的路径- 然后我做了
npm config set node_gyp <path to node-gyp>
之后
npm i node-expat
和npm i
再次工作。