Last updated: Apr 7, 2024
Reading timeยท2 min

To solve the "Parsing error: Cannot find module 'next/babel'" error:
.babelrc file in the root directory of your Next.js project (where
your package.json file is) and add the following code to it.{ "presets": ["next/babel"], "plugins": [] }
You can read more about customizing your Babel config in this section of the docs.
extends property in your .eslintrc file.{ "extends": ["next", "next/core-web-vitals", "prettier"] }
To install the eslint-config-prettier module, open your terminal in your
project's root directory and run the following command.
# ๐๏ธ with NPM npm install --save-dev eslint-config-prettier # ๐๏ธ with YARN yarn add --dev eslint-config-prettier

You can read more about customizing your ESLint config in this section of the docs.
The error also commonly occurs in Visual Studio Code projects that are split between multiple directories.
frontend |---- package.json backend |---- package.json
frontend directory or the backend directory, instead of opening it in the folder that contains both frontend and backend.Alternatively, you can create a .vscode folder in the root directory of your
project and add a settings.json file to it.
frontend |---- package.json backend |---- package.json .vscode |---- settings.json
In your .vscode/settings.json file, add the path to your working directories.
{ "eslint.workingDirectories": [ "./frontend", "./backend" ] }
Make sure to update the path if your working directories are not called
frontend and backend.

Restart your IDE and development server after adding the .vscode/settings.json
file.
If the error is not resolved, try to delete your node_modules and
package-lock.json (not
package.json) files, re-run npm install and restart your IDE.
# ๐๏ธ (Windows) Delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ (macOS/Linux) Delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ Clean your npm cache npm cache clean --force npm install
Make sure to restart your IDE and dev server if the error persists. VSCode often glitches and needs a reboot.
You can learn more about the related topics by checking out the following tutorials: