Next.js: how to ignore/exclude a folder when running "next build"

by Dan Edwards, 22 October 2024

Next.js: how to ignore/exclude a folder when running "next build"

Want to ignore certain folders/directories when running "next build"? Here's the solution - just add the folder to the exclude array in your tsconfig.json (or jsconfig.json):

tsconfig.json
JSON
1{ 
2	...
3	"exclude": ["node_modules", "misc", "work-in-progress"]
4}

Here, the node_modules folder is ignored as usual, and my misc and work-in-progress folders (in the root directory) will be ignored too.

That's it! Next.js will now ignore these folders during the build process.