0

I'm using VS Code for my project and I don't want node_modules folder to be commited in my repository, so I created a .gitignore file to add that folder, but when I make another commit node_modules is still there and git gives me an error when I make a push:

remote: error: File Proyecto2/node_modules/canvas/build/Release/librsvg-2.so.2 is 100.20 MB; this exceeds GitHub's file size limit of 100.00 MB

I put .gitignore file here

I try to add the folder in 2 ways but none works

Nicholas Carey
  • 65,549
  • 13
  • 92
  • 133
  • 1
    Have you already commited the node_modules, and now you just can't push it? If so you need to delete node_modules from your commit, so adding to the .gitignore now is not enough. – randmon Apr 27 '22 at 16:47
  • Try this https://techstacker.com/remove-node_modules-after-adding-gitignore/ – randmon Apr 27 '22 at 16:49

1 Answers1

-1

You just need to

git rm -r ./node_modules
git commit -am "Removed 'node_modules' from repo."
git push

And you should be good to go.

If you want to keep your local node_modules intact, change the git rm command to

git rm -r --cached ./node_modules
Nicholas Carey
  • 65,549
  • 13
  • 92
  • 133
  • If `node_modules` is already in some existing commits (and it is), removing it from *new* commits won't fix the existing commits. (In fact, they cannot *be* fixed and one must rewind and rewrite history so as to stop using the old, bad commits.) – torek Apr 27 '22 at 22:16
  • @torek — `git rm -r` removes the specified files/directories from the repo. It does not remove the history (and you wouldn't necessarily want it to). But having added a `.gitignore` entry for `node_modules`, and having removed the `node_modules` directory and its contents, further commits will no longer include changes to `node_modules` and its children. – Nicholas Carey Apr 28 '22 at 21:01
  • The OP's issue is that the historical commit, now in the repository, is big enough to prevent `git push` to GitHub, so he needs to rewrite history. (I didn't downvote, but perhaps whoever did, did because of that.) – torek Apr 29 '22 at 04:14