I'd like to not include .babelrc during build since SWC is disabled as a replacement for Babel. I only need .babelrc for a plugin for dev testing purposes that is not supported by SWC yet. I am told to check the doc about ignored compiler options but the page is down, and I could not find a solution from the nextjs document on disabling SWC and its feedback thread.
Asked
Active
Viewed 3,259 times
2 Answers
5
Super hacky, but you could modify the build
script in package.json
to temporarily rename the config file before the build then restore it after:
{
"scripts": {
"dev": "next dev",
"build": "mv .babelrc .babel_ && next build; mv .babel_ .babelrc",
"start": "next start",
"lint": "next lint"
}
}
It's not a cross-platform solution, however.

Mark G
- 1,868
- 1
- 6
- 15
-
Will this ignore code coverage during the build? – Menai Ala Eddine - Aladdin Aug 09 '23 at 09:29
-
But when you run `npm run dev` you got the same issue? – Menai Ala Eddine - Aladdin Aug 10 '23 at 07:49
-
@MenaiAlaEddine-Aladdin I don't use Babel, so I don't the know how this workaround affects your situation. You might get better answers over at [Next's discussion forum](https://github.com/vercel/next.js/discussions). – Mark G Aug 10 '23 at 15:09
3
I think you can add .babelrc
to .gitignore
, and it won't be used during build.

Ali AlHussain
- 226
- 1
- 6
-
-
@EdenChan for this specific case, then i think you can use Mark's solution – Ali AlHussain Mar 23 '22 at 13:47