windows下安装 Vue CLI 的坑

官方教程安装命令:

npm install -g @vue/cli

cmd中执行,报错如下:

C:\Users\admin>npm install -g @vue/cli
npm ERR! Unexpected end of JSON input while parsing near '...0.3","mocha":"2.2.5
",'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\admin\AppData\Roaming\npm-cache\_logs\2019-08-06T08_46_25_
849Z-debug.log
npm ERR! Unexpected end of JSON input while parsing near

搜索一通之后,大部分解决方案:

npm cache clean --force

cmd中执行,报错如下:

C:\Users\admin>npm install -g @vue/cli
npm WARN tarball tarball data for typescript@^3.4.5 (sha512-ACzBtm/PhXBDId6a6sDJ
froT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==) seems to b
e corrupted. Trying one more time.
npm ERR! path C:\Users\admin\AppData\Roaming\npm\node_modules\.staging\typescrip
t-0cbfd754\lib\tsserver.js
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\admin\AppData\R
oaming\npm\node_modules\.staging\typescript-0cbfd754\lib\tsserver.js'
npm ERR!  { [Error: EPERM: operation not permitted, unlink 'C:\Users\admin\AppDa
ta\Roaming\npm\node_modules\.staging\typescript-0cbfd754\lib\tsserver.js']
npm ERR!   cause:
npm ERR!    { Error: EPERM: operation not permitted, unlink 'C:\Users\admin\AppD
ata\Roaming\npm\node_modules\.staging\typescript-0cbfd754\lib\tsserver.js'
npm ERR!      errno: -4048,
npm ERR!      code: 'EPERM',
npm ERR!      syscall: 'unlink',
npm ERR!      path:
npm ERR!       'C:\\Users\\admin\\AppData\\Roaming\\npm\\node_modules\\.staging\
\typescript-0cbfd754\\lib\\tsserver.js' },
npm ERR!   stack:
npm ERR!    'Error: EPERM: operation not permitted, unlink \'C:\\Users\\admin\\A
ppData\\Roaming\\npm\\node_modules\\.staging\\typescript-0cbfd754\\lib\\tsserver
.js\'',
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path:
npm ERR!    'C:\\Users\\admin\\AppData\\Roaming\\npm\\node_modules\\.staging\\ty
pescript-0cbfd754\\lib\\tsserver.js',
npm ERR!   parent: '@vue/cli' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or ant
ivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check t
he
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
).
终止批处理操作吗(Y/N)? y
npm ERR! Error: EPERM: operation not permitted, unlink

没有权限,故使用管理员权限运行cmd,执行安装命令,成功:

C:\Windows\system32>npm install -g @vue/cli
C:\Users\admin\AppData\Roaming\npm\vue -> C:\Users\admin\AppData\Roaming\npm\nod
e_modules\@vue\cli\bin\vue.js

> [email protected] postinstall C:\Users\admin\AppData\Roaming\npm\node_modules\@vue
\cli\node_modules\core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfill
ing JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Colle
ctive or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a goo
d job -)


> [email protected] postinstall C:\Users\admin\AppData\Roaming\npm\node_modules
\@vue\cli\node_modules\core-js-pure
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfill
ing JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Colle
ctive or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a goo
d job -)


> [email protected] postinstall C:\Users\admin\AppData\Roaming\npm\node_modules\@
vue\cli\node_modules\protobufjs
> node scripts/postinstall


> [email protected] postinstall C:\Users\admin\AppData\Roaming\npm\node_modules\@vu
e\cli\node_modules\nodemon
> node bin/postinstall || exit 0

Love nodemon? You can now support the project via the open collective:
 > https://opencollective.com/nodemon/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\@vu
e\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)

+ @vue/[email protected]
added 849 packages from 576 contributors in 393.952s

网上其他解决方案:删除 C:\Users\用户名.npmrc,可自行尝试。

你可能感兴趣的:(javascript,vue,npm)