把小程序档下来之后,做了如下操作
1.npm install
报错如下,导致node_modules文件生成不了
E404
npm ERR! 404 Not Found - GET https://registry.npm.taobao.org/@babel/core/-/core-7.11.1.tgz - [not_found] document not found
'@babel/core@https://registry.npm.taobao.org/@babel/core/-/core-7.11.1.tgz' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
或者
npm ERR! code 1
npm ERR! path /Users/XX/node_modules/canvas
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@11.7.0 | darwin | x64
npm ERR! gyp info spawn /usr/bin/python2
npm ERR! gyp info spawn args [ '/Users/XXnode_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/XXnode_modules/canvas/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/XX/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/haoyingjie/.node-gyp/11.7.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/XX/.node-gyp/11.7.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/XX/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/XX/.node-gyp/11.7.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/XX/node_modules/canvas',
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=.' ]
Package pixman-1 was not found in the pkg-config search path.
npm ERR! Perhaps you should add the directory containing pixman-1.pc' npm ERR! to the PKG_CONFIG_PATH environment variable npm ERR! No package 'pixman-1' found npm ERR! gyp: Call to 'pkg-config pixman-1 --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp 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/XX/node_modules/node-gyp/lib/configure.js:345:16)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:188:13)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
npm ERR! gyp ERR! System Darwin 19.5.0
npm ERR! gyp ERR! command "/usr/local/Cellar/node/11.7.0/bin/node" "/Users/XX/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/XX/node_modules/canvas
npm ERR! gyp ERR! node -v v11.7.0
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok
解决办法:切换镜像源,原来电脑使用的是taobao,项目中指定镜像源为npm
使用nrm查看本地镜像源并切换镜像源
1.下载nrm:npm install nrm -g
如果有权限问题,则使用 sudo npm install nrm -g
2.查看可切换的镜像源:nrm ls (*表示正在使用的镜像源)
npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
这个是我本地的镜像源,目前使用的是taobao
切换镜像源为npm:nrm use npm
切换之后,会输出(*****表示镜像地址)
Registry has been set to:*****
表示切换成功,再次nrm ls镜像源变成如下
* npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
重新npm install成功,