npm踩坑問題實戰(zhàn)記錄
悲催的我基本上問題都遇到了。。。。。。
一、npm安裝依賴失敗問題
問題描述:
錯誤信息: unbuild: sill gentlyRm target.inParent = false
后續(xù)會出現長時間停留
問題解決:刪除整個node_modules,重新npm install
二、 npm lockfile報錯
問題描述:
這個是因為版本問題導致的提示信息。
錯誤信息:
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
問題解決:
- 忽略它。這只是一個警告,所發(fā)生的npm只是向package-lock.json文件添加信息。
- npm在生產中降級到舊版本。考慮運行npm版本 6,npm i npm@6 -g 或者 npm -g install npm@6
- 如果已經安裝了一個新版本的npm,要保留較新版本,使用舊版本運行一個npm命令,可以使用npx來執(zhí)行。使用該-p標志來指定npm想要的版本。例如,即使安裝了版本 7 ,運行npx -p npm@6 npm ci,也會使npm ci以npm版本 6運行。
三、npm ERR! code EPERM問題
問題描述:
這是因為在git bash here,vs code等第三方,不以管理員身份運行造成的問題,就根本來說git bash here是windows dos命令封裝過的。但是cmd 以管理員身份運行就需要定位到相應文件夾操作(需要先進入相應盤,再進入相應文件,比較麻煩 ),但是從第三方進入就可以直接在相應文件夾下操作,這樣也比較方便。
錯誤信息:
$ npm install
npm WARN tarball tarball data for typescript@3.0.3 (sha1-SFOz4nXs2qJ/eP2kbcJzp+t
/wcg=) seems to be corrupted. Trying one more time.
npm ERR! path E:\vue-typescript\node_modules\.staging\typescript-10ba8b53\lib\ty
pescriptServices.js
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'E:\vue-typescript\node_m
odules\.staging\typescript-10ba8b53\lib\typescriptServices.js'
npm ERR! { Error: EPERM: operation not permitted, unlink 'E:\vue-typescript\nod
e_modules\.staging\typescript-10ba8b53\lib\typescriptServices.js'
npm ERR! cause:
npm ERR! { Error: EPERM: operation not permitted, unlink 'E:\vue-typescript\n
ode_modules\.staging\typescript-10ba8b53\lib\typescriptServices.js'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'E:\\vue-typescript\\node_modules\\.staging\\typescript-10ba
8b53\\lib\\typescriptServices.js' },
npm ERR! stack: 'Error: EPERM: operation not permitted, unlink \'E:\\vue-types
cript\\node_modules\\.staging\\typescript-10ba8b53\\lib\\typescriptServices.js\'
',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'E:\\vue-typescript\\node_modules\\.staging\\typescript-10ba8b5
3\\lib\\typescriptServices.js',
npm ERR! parent: 'hello-world' }
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
).
問題解決:
需要刪除.npmrc文件
強調:不是nodejs安裝目錄npm模塊下的那個npmrc文件
而是在C:\Users\{賬戶}\下的.npmrc文件
eg: 我的是C:\Users\zhuzhu,下面有一個.npmrc
四、 npm ERR! code EEXIST(文件已存在,拒絕刪除)
問題描述:
npm ERR! code EEXIST
npm ERR! File exists: E:\software\node.js\node_global\vue
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
如提示,加入–force強制執(zhí)行
問題解決:
- 清理緩存
npm cache clean --force 或者清理node_cache緩存 - 重新執(zhí)行全局安裝或者強制執(zhí)行
npm install @vue/cli -g或者npm install -g @vue/cli --force
補充:通過npm命令來刪除node_modules文件夾
首先通過npm安裝刪除工具
npm install rimraf -g
安裝淘寶鏡像后可以使用
cnpm install rimraf -g 命令行語句,速度會更快
在使用刪除命令
rimraf node_modules
這個刪除本項目的node_modules文件可以試試
刪除整個項目的直接找到安裝目錄,把他移到回收站
總結
到此這篇關于npm踩坑問題的文章就介紹到這了,更多相關npm踩坑問題內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
vite配置別名并處理報錯:找不到模塊“xxx”或其相應的類型聲明方法詳解
我在學習vue3+vite+ts的時候,在配置別名這一步的時候遇到了一個問題,這篇文章主要給大家介紹了關于vite配置別名并處理報錯:找不到模塊“xxx”或其相應的類型聲明的相關資料,需要的朋友可以參考下2022-11-11