Every time I create a Next.js app with:
`npx create-next-app@latest`
ESLint immediately starts flashing warnings in all my .js files saying
"Parsing error: Cannot find module 'next/babel' Require stack:
- /Users//node_modules/next/dist/compiled/babel/bundle.js
- /Users//node_modules/next/dist/compiled/babel/eslint-parser.js
- /Users//node_modules/eslint-config-next/parser.js
- /Users//node_modules/@eslint/eslintrc/dist/eslintrc.cjs
Make sure that all the Babel plugins and presets you are using are defined as dependencies or devDependencies in your package.json file. It's possible that the missing plugin is loaded by a preset you are using that forgot to add the plugin to its dependencies: you can workaround this problem by explicitly adding the missing package to your top-level package.json.eslint"
I've tried reinstalling and creating new projects, cleaning cache, restarting VSCode... and nothing works.
I've found other forum threads on Stack Overflow and GitHub saying that you should add this code to your .eslintrc.json file:
{
"extends": ["next/babel","next/core-web-vitals"]
}
However, while this "hack" removes the ESLint highlight errors, it instead causes errors at build/deployment time – or whenever you run npx eslint .
. ESLint then gives this error message:
ESLint couldn't find the config "next/babel" to extend from. Please check that the name of the config is correct.
The config "next/babel" was referenced from the config file in "/Users/henrikangelstig/react-course/21-the-wild-oasis-website/my-react/.eslintrc.json".
Does anyone know of a solution that:
- Removes the error "Parsing error: Cannot find module 'next/babel'"...
- ...But without causing the "ESLint couldn't find the config "next/babel" to extend from" error at build/deployment or when you run
npx eslint .
??