vue-element-admin框架install失败问题
最终解决方案
问题环境
coandeMacBook-Pro:vue-admin-template mac$ node -v
v15.11.0
coandeMacBook-Pro:vue-admin-template mac$ npm -v
7.6.0
coandeMacBook-Pro:vue-admin-template mac$ node-gyp-v
bash: node-gyp-v: command not found
coandeMacBook-Pro:vue-admin-template mac$ node-gyp -v
v8.0.0
coandeMacBook-Pro:vue-admin-template mac$ python -V
Python 2.7.16
错误描述/日志
npm ERR! code 1
npm ERR! path /Users/mac/Desktop/coan/project/vue-admin-template/node_modules/bufferutil
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@3.8.0
npm ERR! gyp info using node@12.19.0 | darwin | x64
npm ERR! gyp info spawn /usr/bin/python2
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/bufferutil/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/mac/.node-gyp/12.19.0/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/mac/.node-gyp/12.19.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/mac/.node-gyp/12.19.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/bufferutil',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.
npm ERR!
npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.
npm ERR!
npm ERR! No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.
npm ERR!
npm ERR! gyp: No Xcode or CLT version detected!
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/node-gyp/lib/configure.js:345:16)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:314:20)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
npm ERR! gyp ERR! System Darwin 20.4.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/mac/Desktop/coan/project/vue-admin-template/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/mac/Desktop/coan/project/vue-admin-template/node_modules/bufferutil
npm ERR! gyp ERR! node -v v12.19.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mac/.npm/_logs/2021-04-28T08_38_20_523Z-debug.log
填坑之路
1、node-gyp
在错误日志中发现
npm ERR! gyp: No Xcode or CLT version detected!
于是,毅然决然npm install node-gyp -g
发现install报错,详情请转 NODE-GYP On macOS
2、python版本
原以为是python版本问题导致gyp重构失败,于是更新了python
但是发现python@3.9还是报这个错,2.7会报其他错误但是也包含npm ERR! code 1
具体python在macOS中的升级操作可以查看文章macOS自带Python2.7版本升级
3、canvas
在某国外论坛看到有老哥说事canvas已知bug,原因好像是因为缺少lib包,但是经过尝试,没有解决
最终解决方案
nrm use npm
,npm install
,npm run dev
成功运行,解决–【需要使用npm自己的源安装】