我正在尝试在我的项目中安装 vue cli,但出现该错误, 我是新的 MacOs 用户。 希望你能帮我修复它并在我的项目中安装 vue cli。
Circus-MBP:TodoApp circus4$ npm i @vue/cli -g
npm ERR! path ../lib/node_modules/@vue/cli/bin/vue.js
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue'
npm ERR! { [Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue']
npm ERR! cause:
npm ERR! { Error: EACCES: permission denied, symlink '../lib/node_modules/@vue/cli/bin/vue.js' -> '/usr/local/bin/vue'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/@vue/cli/bin/vue.js',
npm ERR! dest: '/usr/local/bin/vue' },
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, symlink \'../lib/node_modules/@vue/cli/bin/vue.js\' -> \'/usr/local/bin/vue\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '../lib/node_modules/@vue/cli/bin/vue.js',
npm ERR! dest: '/usr/local/bin/vue' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Circus4/.npm/_logs/2019-10-07T12_38_25_842Z-debug.log
请您参考如下方法:
您似乎没有全局安装所需的权限。您可以尝试使用 sudo 安装或(推荐)将 NPM 的默认目录移动到您具有读/写权限的目录:
在您的主目录中创建目录,比如
~/.npm-global
。运行
npm config set prefix '~/.npm-global'
更新您的
PATH
:export PATH=~/.npm-global/bin:$PATH
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
请注意,虽然您可能只使用 sudo,但强烈建议不要这样做。它甚至在您发布的错误输出中这样说:
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).