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

by Dan Edwards

Learn how to configure Next.js to ignore or exclude specific folders or directories during build time using tsconfig.json.

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.

Published Tuesday, 22 October 2024