Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

ESLint fails with: Cannot find module 'next/babel'

ErrorParsing error: Cannot find module 'next/babel'

Short answer

next/babel is a Babel preset that ships inside the next package. ESLint reports that it cannot find it when the parser reads a Babel config that names the preset but next is not installed where Babel looks, or when an old @babel/eslint-parser setup is still in your ESLint config. Install dependencies in the right folder, or replace the legacy setup with eslint-config-next.

  • Applies to Next.js 15, Next.js 16, ESLint 9, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find which file asks for the preset, and whether next can be resolved from the folder where ESLint runs. The two commands show the Babel config in the project and the installed Next.js version.

    ls .babelrc* babel.config.* 2>/dev/null
    grep -rn "next/babel" .babelrc* babel.config.* .eslintrc* eslint.config.* package.json 2>/dev/null
    npm ls next
  2. 2Match what you see, then jump to its fix

    1. 1npm ls next prints (empty) or a different folder than the one you run eslint in, for example in a fresh clone, a CI job without install, or a monorepo package.next is not installed where Babel looks for the presetFix
    2. 2Your ESLint config has parser: '@babel/eslint-parser', or a babelOptions block that lists next/babel.An old @babel/eslint-parser setup is still configuredFix
    3. 3A .babelrc or babel.config.js exists that you did not write on purpose, and it only contains next/babel.A leftover .babelrc keeps naming the presetFix

What does the error look like?

  • Parsing error: Cannot find module 'next/babel'
  • ESLint stops on the first file with a Babel or parser error instead of listing lint results

Cause 1 of 3

next is not installed where Babel looks for the preset

1Check

The preset is part of the next package. A Babel config that lists next/babel only works when next is installed and reachable from that project.

npm ls next

2Fix

Install dependencies in the project that owns the Babel config, then run ESLint from there. In a monorepo, run the install at the workspace root and run the linter inside the app that depends on next.

npm install
npx eslint .

3Verify

The parsing error is gone and ESLint prints real lint results.

npx eslint . --max-warnings=0

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

An old @babel/eslint-parser setup is still configured

1Check

By default @babel/eslint-parser loads the project's Babel config (requireConfigFile is true), which is why a Babel preset can fail inside a lint run.

grep -rn "babel-parser\|eslint-parser\|babelOptions" .eslintrc* eslint.config.* package.json 2>/dev/null

2Fix

Use the Next.js ESLint package instead. It brings the Next.js, React and React Hooks rules, and the setup no longer depends on a Babel file. Remove the parser lines you added by hand.

npm i -D eslint eslint-config-next

// eslint.config.mjs
import { defineConfig, globalIgnores } from 'eslint/config'
import nextVitals from 'eslint-config-next/core-web-vitals'

export default defineConfig([
  ...nextVitals,
  globalIgnores(['.next/**', 'out/**', 'build/**', 'next-env.d.ts']),
])

3Verify

Run ESLint with the CLI.

npx eslint .

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

A leftover .babelrc keeps naming the preset

1Check

A custom Babel file makes Next.js compile with Babel instead of SWC, and the file is then the source of truth, so it must name next/babel itself.

cat .babelrc
git log --oneline -- .babelrc | head -3

2Fix

Delete the file if nothing needs a custom Babel plugin; Next.js then uses SWC again. If you do need Babel, keep it with next/babel as the preset, and make sure next is installed (first cause).

# only if no custom Babel plugin is needed
rm .babelrc

// .babelrc when Babel is required
{ "presets": ["next/babel"] }

3Verify

Run the dev server and ESLint. Neither mentions the preset.

npx next build
npx eslint .

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Commit the lockfile and install with npm ci in CI before linting.
  • Use eslint-config-next with the ESLint CLI instead of a hand-written parser setup.
  • Delete .babelrc files that nobody needs; SWC is the default compiler.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.