4

I run my nextjs project by

npm run dev

NOT

npm run build

but it automatically create the .next folder. and after I tried to delete that folder but it automatically generated again. why??

I don't expect to generate the .next folder by this command:

npm run dev
Mustafa Zahedi
  • 103
  • 1
  • 1
  • 9
  • 5
    Because thats how nextjs works, both build and dev commands generates (SSR stuff and other) files which will be stored in same `.next` directory but file contents will be different. – bogdanoff Mar 31 '22 at 06:58
  • You can also add the directory to your .gitignore file if you don't want to track it – Ian Andwati Mar 31 '22 at 07:19
  • 1
    So what is the problem? don't delete it. it is because next works like this. – Zia Yamin Apr 07 '22 at 03:52

2 Answers2

4

You are running your project with

npm run dev

Once the project is launched, .next folder will be created to store page cache and some features to speed up your project. While project running, some files will be added to .next folder during your dev usage. If you delete you .next folder during usage, you will have errors on the pages - you should restart your npm run dev

illia chill
  • 1,652
  • 7
  • 11
1

You can delete .next folder and when you do npm run dev again, it will recreate it

Calvin
  • 194
  • 17