大家在安装仓库依赖时是否遇到过 node-gyp 报错的问题,错误信息大致如下:
node_modules/.pnpm/tree-sitter-json@0.20.0/node_modules/tree-sitter-json: Running install script, failed in 586ms
.../node_modules/tree-sitter-json install$ node-gyp rebuild
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.1.0
│ gyp info using node@16.19.1 | darwin | x64
│ gyp info find Python using Python version 3.8.10 found at "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
│ gyp WARN install got an error, rolling back install
│ gyp ERR! configure error
│ gyp ERR! stack Error: ENOENT: no such file or directory, stat '/tmp/node-v14.17.6-headers.tar.gz'
│ gyp ERR! System Darwin 22.6.0
│ gyp ERR! command "/Users/wangminghui/.nvm/versions/node/v16.19.1/bin/node" "/usr/local/Cellar/pnpm/7.11.0/libexec/dist/node_modules/node-gyp/bin/node-gyp.js"
│ gyp ERR! cwd /Users/wangminghui/Documents/xylink-projects/yapi/node_modules/.pnpm/tree-sitter-json@0.20.0/node_modules/tree-sitter-json
│ gyp ERR! node -v v16.19.1
│ gyp ERR! node-gyp -v v9.1.0
│ gyp ERR! not ok
└─ Failed in 586ms
node_modules/.pnpm/tree-sitter-yaml@0.5.0/node_modules/tree-sitter-yaml: Running install script, failed in 561ms
.../node_modules/tree-sitter-yaml install$ node-gyp rebuild
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@9.1.0
│ gyp info using node@16.19.1 | darwin | x64
│ gyp info find Python using Python version 3.8.10 found at "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
│ gyp WARN install got an error, rolling back install
│ gyp ERR! configure error
│ gyp ERR! stack Error: ENOENT: no such file or directory, stat '/tmp/node-v14.17.6-headers.tar.gz'
│ gyp ERR! System Darwin 22.6.0
│ gyp ERR! command "/Users/wangminghui/.nvm/versions/node/v16.19.1/bin/node" "/usr/local/Cellar/pnpm/7.11.0/libexec/dist/node_modules/node-gyp/bin/node-gyp.js"
│ gyp ERR! cwd /Users/wangminghui/Documents/xylink-projects/yapi/node_modules/.pnpm/tree-sitter-yaml@0.5.0/node_modules/tree-sitter-yaml
│ gyp ERR! node -v v16.19.1
│ gyp ERR! node-gyp -v v9.1.0
│ gyp ERR! not ok
└─ Failed in 561ms
node_modules/.pnpm/fsevents@1.1.2/node_modules/fsevents: Running install script...
node_modules/.pnpm/node-sass@4.14.1/node_modules/node-sass: Running install script...
node_modules/.pnpm/react-slick@0.17.1_wcqkhtmu7mswc6yz4uyexck3ty/node_modules/react-slick: Running postinstall script...
ELIFECYCLE Command failed with exit code 1.
找不到 /tmp/node-v14.17.6-headers.tar.gz 文件,确实这个目录下没有这个文件,不清楚为啥要找这个目录下的压缩包,我用的 nvm 管理 node 版本,默认是 v14.17.6,但当前使用的是 v16.19.1,Mac环境。这个项目是 yapi 的官方仓库,但一直下载不好依赖,求助 🙏🙏
找到原因了,不清楚啥时候在全局的 .npmrc 配置文件中添加了 tarball 参数:
把这个配置去掉即可,还有就是使用 yapi 官方推荐的 node 版本,我使用了 v8.17.0(太老了😭)可以跑起来。
相关链接:https://stackoverflow.com/questions/42722457/how-to-prevent-node-gyp-from-downloading-node-headers-tar-gz-and-node-lib-from-i