使用npm install安装依赖之后,有时候存在网络或其他问题安装不上个别依赖,其项目失败,报错
当启项目时报错:Error: EPERM: operation not permitted, unlink
15555 error code EPERM
15556 error syscall unlink
15557 error path F:\vue\vuedemo06\node_modules\.staging\html-entities-f752483c\LICENSE
15558 error errno -4048
15559 error Error: EPERM: operation not permitted, unlink 'F:\vue\vuedemo06\node_modules\.staging\html-entities-f752483c\LICENSE'
15559 error [OperationalError: EPERM: operation not permitted, unlink 'F:\vue\vuedemo06\node_modules\.staging\html-entities-f752483c\LICENSE'] {
15559 error cause: [Error: EPERM: operation not permitted, unlink 'F:\vue\vuedemo06\node_modules\.staging\html-entities-f752483c\LICENSE'] {
15559 error errno: -4048,
15559 error code: 'EPERM',
15559 error syscall: 'unlink',
15559 error path: 'F:\\vue\\vuedemo06\\node_modules\\.staging\\html-entities-f752483c\\LICENSE'
15559 error },
有两种方法:
1、直接删除缓存文件,删除C:\Users\.npmrc 这个文件
2、运行命令行,清除缓存
npm cache clean --force
之后在进行npm install安装就行,要是网络比较慢使用淘宝镜像链接安装
npm install --registry=https://registry.npm.taobao.org
或者安装cnpm使用cnpm安装
npm install cnpm -g --registry=https://registry.npm.taobao.org
使用yarn serve启动项目的时候,启动项目失败,报错:SyntaxError: Unexpected token '.'
SyntaxError: Unexpected token '.'
C:\Users\86156\Desktop\vue3_cli_test1\node_modules\@vue\compiler-core\dist\compiler-core.cjs.js:3261
if (grandparent?.source) {
^
SyntaxError: Unexpected token '.'
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\86156\Desktop\Vue3学习\vue3_cli_test1\node_modules\@vue\compiler-core\index.js:6:20)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loadenpm ERR! code ELIFECYCLE
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\86156\AppData\Roaming\npm-cache\_logs\2022-05-20T07_18_15_942Z-debug.log
我看了一下自己的node版本是12.0.0,后来将node版本升级到18.14.0后就可以正常运行了!!
切换node版本我是用的是nvm
使用管理者方式打开cmd
1、安装nvmbrew install nvm
2、使用nvm安装node版本: nvm isntall node安装指定版本 nvm install 8.16.0
3、查看所有版本 nvm ls
4、切换node版本 nvm use node使用指定版本 nvm use 10.16.2