6

how can I delete all node_modules folders from all packages in an npm 7 workspace?

With Lerna we could just execute lerna clean -y but when migrating to native NPM 7+ workspaces, is there some equivalent?

mesqueeb
  • 5,277
  • 5
  • 44
  • 77

3 Answers3

13

you can execute this to do so:

npm exec --workspaces -- npx rimraf node_modules && npx rimraf node_modules

explanation:

  • npm exec will execute whatever comes next
  • --workspaces will execute it in all your packages in your monorepo
  • -- means "here comes the command to execute"
  • npx rimraf node_modules is the command that's executed in all packages: it means it will delete the node_modules folder
  • && means "and then"
  • npx rimraf node_modules is executed again so the root folder node_modules also get deleted

That's all! Good luck

mesqueeb
  • 5,277
  • 5
  • 44
  • 77
4

From this video on How to delete node modules like a pro.

npx npkill
cigien
  • 57,834
  • 11
  • 73
  • 112
Yisheng Jiang
  • 110
  • 1
  • 5
0

In lerna@7 Run the below command as mentioned here!

npx lerna clean -y