【问题标题】:How do I delete properly node_modules from Mac?如何从 Mac 中正确删除 node_modules?
【发布时间】:2022-01-01 22:27:00
【问题描述】:

我的 Mac 空间不足。当我一次运行许多项目时,我总是首先查看 node_modules 目录 - 我相信我们都这样做!

我不确定是应该全部清除还是保持全局安装。转到您安装了node_modules 的目录并打印它们/这是我所做的:

$ find . -name "node_modules" -type d -prune -print | xargs du -chs

结果:

5.4M    ./.npm-packages/lib/node_modules
 19M    ./.nvm/versions/node/v15.3.0/lib/node_modules
2.4M    ./Desktop/note/server/node_modules
 59M    ./Desktop/jsamazona/frontend/node_modules
6.3M    ./Desktop/jsamazona/node_modules
228M    ./Desktop/react-with-leaflet-master/node_modules
254M    ./Desktop/npmapp/npmapp/node_modules
311M    ./Desktop/npmapp/node_modules
387M    ./Desktop/speechly_expense_tracker_project-main/node_modules
347M    ./Desktop/my-gatsby-project/node_modules
du: ./Desktop/PORTFOLIOS/bootstrap: No such file or directory
du: portfolio/node_modules: No such file or directory
 98M    ./Desktop/PORTFOLIOS/simplefolio/node_modules
305M    ./Desktop/PORTFOLIOS/myportfoliosite/node_modules
 81M    ./Desktop/PORTFOLIOS/portfolio20/node_modules
421M    ./Desktop/PORTFOLIOS/vania-portfolio/node_modules
706M    ./Desktop/PORTFOLIOS/portfolio/node_modules
 81M    ./Desktop/PORTFOLIOS/myportfolio/node_modules
302M    ./Desktop/PORTFOLIOS/portfoliob/studio/node_modules
344M    ./Desktop/PORTFOLIOS/portfoliob/node_modules
595M    ./Desktop/PORTFOLIOS/vdfolio/node_modules
584M    ./Desktop/PORTFOLIOS/vdfolio/vdfolio-api/node_modules
584M    ./Desktop/PORTFOLIOS/vdfolio/vdfolio/node_modules
261M    ./Desktop/recipeui/node_modules
291M    ./Desktop/recipeui/DEVTODO/quizapp/node_modules
716K    ./Desktop/recipeui/DEVTODO/LOco/node_modules
389M    ./Desktop/GATSBYS/gatsby-bloga/node_modules
467M    ./Desktop/GATSBYS/gatsby-bootcamp/node_modules
457M    ./Desktop/GATSBYS/my-gatsby-project/node_modules
510M    ./Desktop/GATSBYS/gatsby-simplefolio/node_modules
295M    ./Desktop/GATSBYS/gotsbystyle/node_modules
4.0K    ./Desktop/yarn/node_modules
100K    ./Desktop/project_chat_application/node_modules
368M    ./Desktop/react-three/node_modules
6.5M    ./Desktop/MAP/node_modules
260M    ./Desktop/MAP/map/node_modules
501M    ./Desktop/wwwg/node_modules
259M    ./Desktop/DEPLOYED/todo/node_modules
739M    ./Desktop/DEPLOYED/ecommerce2/node_modules
435M    ./Desktop/DEPLOYED/gatsby-simplefolio/node_modules
275M    ./Desktop/DEPLOYED/mern-tracker/node_modules
303M    ./Desktop/DEPLOYED/mern-tracker/mern-tracker/node_modules
 14M    ./Desktop/DEPLOYED/mern-tracker/mern-tracker/backend/node_modules
584M    ./Desktop/DEPLOYED/vdfolio/node_modules
311M    ./Desktop/covidtr/covidtr/node_modules
267M    ./Desktop/recepapp/node_modules
294M    ./Desktop/vdapp/node_modules
255M    ./Desktop/threeui/node_modules
584M    ./Desktop/my-project/node_modules
554M    ./Desktop/my-project/my-project/node_modules
du: ./Desktop/node-express: No such file or directory
du: /server/node_modules: No such file or directory
du: ./Desktop/node-express: No such file or directory
du: /server/memo-pad2/node_modules: No such file or directory
du: ./Desktop/node-express: No such file or directory
du: /client/node_modules: No such file or directory
 16M    ./Desktop/tinder/tinder-backend/node_modules
372M    ./Desktop/tinder/tinder/node_modules
249M    ./Desktop/house3D/house3d/node_modules
354M    ./Desktop/mernshop/frontend/node_modules
 59M    ./Desktop/mernshop/node_modules
 15M    ./Desktop/mernblog/server/node_modules
356M    ./Desktop/mernblog/client/node_modules
du: ./Library/Application: No such file or directory
du: Support/vscode-sqltools/node_modules: No such file or directory
106M    ./Library/Caches/typescript/4.1/node_modules
210M    ./Library/Caches/typescript/4.0/node_modules

清单太长了,我该怎么办?

我正在考虑删除所有节点并重新安装。

$ find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

Thomas Large 的建议how to delete all node_modules on Mac

【问题讨论】:

    标签: macos npm node-modules


    【解决方案1】:

    如果这只是在本地开发项目中并且您自己安装了它们,您可以运行 rm -Rf node_modules 删除它们,然后在准备好时运行 npm install 重新安装。

    【讨论】:

    • 不,不是,这是在我的整个系统中,所有项目中,我复制/粘贴了一点,这将是一个漫长的故事。我试图在 npm.js 上发布我自己的 package.json 并以某种方式将主机名/IPrequest 弄乱了 registry.npmjs.org/express 失败,原因:主机名/IP 与证书的替代名称不匹配。所以,想法是重新安装节点,希望能解决它。
    【解决方案2】:

    如果您想从您的机器中删除所有节点模块文件夹,或者从任何目录及其所有子目录中删除,以下命令可以使用:

    # MACOS
    cd <directoryToDeleteFrom>
    find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
    
    # WINDOWS
    cd <directoryToDeleteFrom>
    FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"
    
    # POWERSHELL
    Get-ChildItem -Path "." -Include "node_modules" -Recurse -Directory | Remove-Item -Recurse -Force
    

    归功于trillion.io

    然后,只要您使用带有npm install 等的特定项目,就可以重新安装节点模块,或者为了节省空间,您可以尝试pnpm(尽管我在它和特定项目方面遇到了错误,例如反应原生)。

    【讨论】:

      【解决方案3】:

      如果您想清理驱动器上的一些空间,您也可以查找临时文件和此类数据以节省一些空间。

      【讨论】:

      • 或使用清理应用程序,它会做得更好,问题是 node_modules 使我的系统过载,我可以删除所有它们并从头开始。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      • 2021-03-27
      • 1970-01-01
      • 1970-01-01
      • 2013-10-13
      • 2017-07-02
      相关资源
      最近更新 更多