1. 程式人生 > 其它 >刪除node_modules重新安裝

刪除node_modules重新安裝

技術標籤:VSCode筆記前端nodenpm

刪除node_modules重新安裝

我們在開發專案的時候,每次安裝的 node 包會出現版本和專案所需要的版本不一致的問題。因此需要刪除 node 包,重新安裝它,很多小夥伴只是把他給手動刪除了,但是卻沒有刪除包的快取,因此在啟動專案的時候還是會報錯~
接篇文章就是簡單直接明瞭的告訴大家詳細操作步驟

針對於 Windows 系統

第一步:在專案需要安裝 node_modules 的目錄下

在這裡插入圖片描述

第二步:先安裝 rimraf 工具

npm install -g rimraf

第三步:刪除 node_modules 包和 package-lock.json 檔案

rimraf node_modules
rimraf package-lock.json

注意:node_modules 和package-lock.json 都需要刪除,如果只刪除 node_modules 也是不可以的。

第四步:清除快取

npm cache clear --force

第五步:重新安裝依賴包

安裝完成會自動生成 package-lock.json 檔案

npm config set registry [https://registry.npm.taobao.org]

npm install

第六步:重啟專案