3

I wanna push my NextJS Project to GitHub but I always get an error that says my .next/cache folder exceeds GitHub's file size limit.

I tried to solve this by adding the next folder to the .gitignore file.

This is my .gitignore file

node_modules
next
.env

Then I followed this steps:

  1. Make changes in .gitignore file
  2. Run git rm -r --cached . command.
  3. Run git add . command
  4. git commit -m "Commit message" or just git commit or continue working.
  5. git push

But it still didn't work.

Error that I got

remote: error: File .next/cache/webpack/client-development/32.pack is 122.93 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .next/cache/webpack/client-development/71.pack is 126.09 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File .next/cache/webpack/client-development/9.pack is 155.84 MB; this exceeds GitHub's file size limit of 100.00 MB

Did I write something wrong in my .gitignore file or is there another problem?

Thank's for helping out!

Holunderyogele
  • 394
  • 6
  • 15

3 Answers3

2

I strongly suspect that the problem is that the files may have been deleted, but they still exist in the history of the repository between when you last pushed and now. A file that's committed and then deleted in a later commit still exists in the repository history.

In order to resolve the issue you'll therefore need to remove them from the repository history entirely. https://docs.github.com/en/github/managing-large-files/working-with-large-files/removing-files-from-a-repositorys-history provides some guidance on doing this.

Matthew Daly
  • 8,864
  • 2
  • 39
  • 80
1

next and .next are different folders.

  • Indeed, it looks like OP's `.gitignore` file should have had `.next` instead of `next`, before they did their `git add .`. – joanis Nov 17 '21 at 14:12
1

The only thing that worked for me was this:

git rm --cached .next/ -r

Then checking git status

git status

Check how far ahead you are

On branch master
Your branch is ahead of 'origin/master' by 8 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

Then run the following appending how far ahead you are

git reset HEAD~8

Then:

git add .
git commit -m "bug fix"
git push -u origin main 
cormacncheese
  • 463
  • 4
  • 12