win10下vue-cli3.x全局安裝失敗問題解決

win10下vue-cli3.x全局安裝失敗問題解決

問題重現

安裝vue-cli3.x版本:

npm install -g @vue/cli

問題日誌

11987 verbose stack Error: EPERM: operation not permitted, lstat 'E:\nodejs\npm_global_modules\node_modules\node_modules\.staging\typescript-f57f55fd\lib\tsc.js'
11988 verbose cwd C:\WINDOWS\system32
11989 verbose Windows_NT 10.0.17134
11990 verbose argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "@vue/cli"
11991 verbose node v10.15.3
11992 verbose npm  v6.4.1
11993 error path E:\nodejs\npm_global_modules\node_modules\node_modules\.staging\typescript-f57f55fd\lib\tsc.js
11994 error code EPERM
11995 error errno -4048
11996 error syscall lstat
11997 error Error: EPERM: operation not permitted, lstat 'E:\nodejs\npm_global_modules\node_modules\node_modules\.staging\typescript-f57f55fd\lib\tsc.js'
11997 error  { [Error: EPERM: operation not permitted, lstat 'E:\nodejs\npm_global_modules\node_modules\node_modules\.staging\typescript-f57f55fd\lib\tsc.js']
11997 error   cause:
11997 error    { Error: EPERM: operation not permitted, lstat 'E:\nodejs\npm_global_modules\node_modules\node_modules\.staging\typescript-f57f55fd\lib\tsc.js'
11997 error      errno: -4048,
11997 error      code: 'EPERM',
11997 error      syscall: 'lstat',
11997 error      path:
11997 error       'E:\\nodejs\\npm_global_modules\\node_modules\\node_modules\\.staging\\typescript-f57f55fd\\lib\\tsc.js' },
11997 error   stack:
11997 error    'Error: EPERM: operation not permitted, lstat \'E:\\nodejs\\npm_global_modules\\node_modules\\node_modules\\.staging\\typescript-f57f55fd\\lib\\tsc.js\'',
11997 error   errno: -4048,
11997 error   code: 'EPERM',
11997 error   syscall: 'lstat',
11997 error   path:
11997 error    'E:\\nodejs\\npm_global_modules\\node_modules\\node_modules\\.staging\\typescript-f57f55fd\\lib\\tsc.js',
11997 error   parent: '@vue/cli' }
11998 error The operation was rejected by your operating system.
11998 error It's possible that the file was already in use (by a text editor or antivirus),
11998 error or that you lack permissions to access it.
11998 error
11998 error If you believe this might be a permissions issue, please double-check the
11998 error permissions of the file and its containing directories, or try running
11998 error the command again as root/Administrator (though this is not recommended).
11999 verbose exit [ -4048, true ]

問題分析

error Error: EPERM: operation not permitted
該錯誤根據提示信息:error or that you lack permissions to access it. 分析可能是權限問題,採用管理員運行cmd,執行安裝vue-cli,仍然出現上述錯誤。排除權限問題。再次分析日誌文件,懷疑是npm安裝包緩存衝突,清空緩存:

npm cache clean --force

結果仍然無效。最後懷疑是npm源的問題,之前設置爲阿里源,於是切換到官方源。
npm config set registry http://registry.npmjs.org
再次安裝。問題解決。

問題解決

由於npm源在國內使用可能不太穩定,下載也比較慢,通常都用國內的阿里源來代替官方源,但是有時候安裝某些新的工具,比如vue-cli3.x,使用阿里源可能會有些問題。這時切換爲官方源,可能問題能夠解決。這裏分析可能原因是阿里源基於的node版本可能落後於本地安裝的node版本,所以對於新的依賴包可能用官方源反而可以下載下來。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章