sanity icon indicating copy to clipboard operation
sanity copied to clipboard

Parsing error: Cannot find module 'next/babel' Require stack

Open Bidmon1234 opened this issue 2 years ago • 5 comments

Parsing error: Cannot find module 'next/babel' Require stack:

  • C:\Users\bidyu\Downloads\react-app-1st\panda\node_modules\next\dist\compiled\babel\bundle.js
  • C:\Users\bidyu\Downloads\react-app-1st\panda\node_modules\next\dist\compiled\babel\eslint-parser.js
  • C:\Users\bidyu\Downloads\react-app-1st\panda\node_modules\eslint-config-next\parser.js
  • C:\Users\bidyu\Downloads\react-app-1st\panda\node_modules@eslint\eslintrc\dist\eslintrc.cjseslint

Bidmon1234 avatar Jun 09 '22 17:06 Bidmon1234

Solution 1:

Create a file called .babelrc in your root directory and add this code

{ "presets": ["next/babel"], "plugins": [] }

And in .eslintrc replace the existing code with

{ "extends": ["next/babel"] }

Solution 2: You need to install npm with this command:

npm install --save-dev @babel/core @babel/preset-env
npm install --save-dev @babel/core

morshedulmunna avatar Jun 11 '22 16:06 morshedulmunna

in root directory we have to install npm install --save-dev @babel/core @babel/preset-env and npm install --save-dev @babel/core @morshedulmunna ??

Pavitra554 avatar Aug 03 '22 12:08 Pavitra554

i added this "eslint.workingDirectories": ["./web", "./studio"] line in .eslintrc and it worked for me

.eslintrc looks like this { "extends": "@sanity/eslint-config-studio", "eslint.workingDirectories": ["./web", "./studio"] }

@morshedulmunna @judofyr @Bidmon1234 @sjelfull

Pavitra554 avatar Aug 03 '22 13:08 Pavitra554

For me, this was an issue with the VS Code ESLint extension when you have the nextjs app in a subfolder (app subfolder in my case) from the root. To solve it, I created a .vscode folder in the root with a file settings.json and this contents

{
  "eslint.workingDirectories": ["./app", "./another-app"]
}

This only works this way if you're using the VS Code "workspace". If you've loaded the parent folder with a lot of subfolders, you'll need to create the .vscode/settings.json in your parent folder, but then add in the folder path to the start, so

{
  "eslint.workingDirectories": ["./folder/app", "./folder/another-app"]
}

sambenskin avatar Sep 07 '22 11:09 sambenskin

This was helpful, thanks.

saurabhranjan007 avatar Sep 09 '22 14:09 saurabhranjan007

My Problem

I found this error in project with PNPM, ESLint, and Monorepo architecture using Turborepo.

My Solution

add this into the ESLint config file:

parserOptions: {
    babelOptions: {
      presets: [require.resolve('next/babel')],
    },
  },

ImBIOS avatar Jan 26 '23 06:01 ImBIOS

i added this "eslint.workingDirectories": ["./web", "./studio"] line in .eslintrc and it worked for me

.eslintrc looks like this { "extends": "@sanity/eslint-config-studio", "eslint.workingDirectories": ["./web", "./studio"] }

@morshedulmunna @judofyr @Bidmon1234 @sjelfull

Thanks, this worked for me....

Oladips avatar Jan 26 '23 08:01 Oladips