node.js報(bào)錯(cuò):npm?ERR?code?EPERM的解決過(guò)程
1 完整錯(cuò)誤
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\NodeJS\node_cache\_cacache\tmp\7bbab18e
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\7bbab18e'
npm ERR! at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR! at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR! at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR! at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR! at async Promise.all (index 1)
npm ERR! at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR! at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5)
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\7bbab18e'
npm ERR! at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR! at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR! at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR! at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR! at async Promise.all (index 1)
npm ERR! at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR! at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5) {
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'D:\\NodeJS\\node_cache\\_cacache\\tmp\\7bbab18e',
npm ERR! type: 'system',
npm ERR! requiredBy: '.'
npm ERR! }
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 antivirus),
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 the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
(base) PS F:\tutorial-frontend\webpack\code> npm i webpack webpack-cli --save-dev
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\NodeJS\node_cache\_cacache\tmp\671f2a33
npm ERR! errno EPERM
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\671f2a33'
npm ERR! at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR! at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR! at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR! at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR! at async Promise.all (index 1)
npm ERR! at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR! at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5)
npm ERR! FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/webpack: EPERM: operation not permitted, open 'D:\NodeJS\node_cache\_cacache\tmp\671f2a33'
npm ERR! at D:\NodeJS\node_modules\npm\node_modules\minipass-fetch\lib\body.js:162:15
npm ERR! at async Arborist.[nodeFromEdge] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
npm ERR! at async Arborist.[buildDepStep] (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)
npm ERR! at async Arborist.buildIdealTree (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:216:7)
npm ERR! at async Promise.all (index 1)
npm ERR! at async Arborist.reify (D:\NodeJS\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\reify.js:149:5)
npm ERR! at async Install.install (D:\NodeJS\node_modules\npm\lib\install.js:170:5) {
npm ERR! code: 'EPERM',
npm ERR! syscall: 'open',
npm ERR! path: 'D:\\NodeJS\\node_cache\\_cacache\\tmp\\671f2a33',
npm ERR! type: 'system',
npm ERR! requiredBy: '.'
npm ERR! }
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 antivirus),
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 the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
2 錯(cuò)誤詳解
該錯(cuò)誤發(fā)生在修改npm的全局安裝路徑之后,再執(zhí)行npm install 包 -g或是npm install 包時(shí)發(fā)生,但是在管理員身份下運(yùn)行cmd,均能執(zhí)行成功。
2.1 修改npm全局安裝:
1.命令行:
npm config set prefix "D:\NodeJS\node_global" npm config set cache "D:\NodeJS\node_cache"
在C盤(pán)User/用戶名/下有一個(gè).npmrc的文件
2.將上述node_global文件夾的路徑加入環(huán)境變量
2.2 導(dǎo)致該安裝問(wèn)題的原因
沒(méi)有管理員權(quán)限,無(wú)法在node_global和node_cache兩個(gè)文件夾下進(jìn)行一些必要的操作
2.3 修復(fù)方法
- 刪除用戶下的.npmrc文件,即不改變?nèi)职惭b的路徑(不夠好,本質(zhì)問(wèn)題仍沒(méi)有解決,全局還是會(huì)安裝在C盤(pán))
- 每次都用管理員身份運(yùn)行命令行(不夠方便,vscode 下的命令行默認(rèn)也不是管理員身份運(yùn)行的)
- 直接修改
node_global和node_cache文件夾的權(quán)限:
右鍵文件夾,打開(kāi)屬性,切換到安全選項(xiàng)卡

選擇編輯,將沒(méi)有打鉤的位置全部打上鉤(即將其它用戶的權(quán)限設(shè)置為與管理員相同),應(yīng)用即可。
3 運(yùn)行測(cè)試
安裝webpack測(cè)試,成功!
npm i webpack webpack-cli -g npm i webpack webpack-cli --save-dev
總結(jié)
到此這篇關(guān)于node.js報(bào)錯(cuò):npm ERR code EPERM解決的文章就介紹到這了,更多相關(guān)node.js報(bào)錯(cuò)npm ERR code EPERM內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Express + Session 實(shí)現(xiàn)登錄驗(yàn)證功能
本文主要介紹在 Express 框架中,如何使用 Session 來(lái)實(shí)現(xiàn)用戶登錄身份驗(yàn)證。對(duì)express session實(shí)現(xiàn)登錄驗(yàn)證相關(guān)知識(shí),感興趣的朋友一起看看吧2017-09-09
nodejs讀寫(xiě)json文件的簡(jiǎn)單方法(必看)
下面小編就為大家?guī)?lái)一篇nodejs讀寫(xiě)json文件的簡(jiǎn)單方法(必看)。2017-03-03
node.js中的fs.rename方法使用說(shuō)明
這篇文章主要介紹了node.js中的fs.rename方法使用說(shuō)明,本文介紹了fs.rename的方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下的相關(guān)資料2014-12-12
windows系統(tǒng)下安裝yarn的詳細(xì)教程
yarn是一個(gè)新的JS包管理工具,它的出現(xiàn)是為了彌補(bǔ)npm的一些缺陷,下面這篇文章主要給大家介紹了關(guān)于windows系統(tǒng)下安裝yarn的詳細(xì)教程,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
Node.js 獲取微信JS-SDK CONFIG的方法示例
這篇文章主要介紹了Node.js 獲取微信JS-SDK CONFIG的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
Node中的util.promisify()方法的基本使用和實(shí)現(xiàn)
眾所周知,在JS中實(shí)現(xiàn)異步編程主要是通過(guò)以下幾種方案,回調(diào)函數(shù),觀察者模式,Generator,Promise,async / await ,今天就和大家一起聊一下在node中的一個(gè)util.promisify()這個(gè)API的基本使用和基本實(shí)現(xiàn)2023-07-07
nodejs結(jié)合Socket.IO實(shí)現(xiàn)的即時(shí)通訊功能詳解
這篇文章主要介紹了nodejs結(jié)合Socket.IO實(shí)現(xiàn)的即時(shí)通訊功能,結(jié)合實(shí)例形式詳細(xì)分析了nodejs結(jié)合Socket.IO實(shí)現(xiàn)即時(shí)通訊的相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2018-01-01
利用adb shell和node.js實(shí)現(xiàn)抖音搶紅包功能(推薦)
這篇文章主要介紹了利用adb shell和node.js實(shí)現(xiàn)抖音搶紅包功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-02-02

