'Sanity Studio: Parsing Error for Babel Preset Env

I'm new to working with Sanity, and just set up a project. Everything is working fine, however, in Visual Studio Code, I keep getting a parsing error that won't disappear, and I'm wondering how I can fix it.

Parsing error: Cannot find module '@babel/preset-env'

I've tried deleting the node_modules and re-running sanity install, I've also tried using npm install to install @babel/core and @babel/preset-env. Nothing seems to have fixed the problem so far.

Any suggestions? I want to start using Sanity with my team at work, but having this error is really quite annoying (as everything is underlined in red).



Solution 1:[1]

I was having a similar issue. For me, the issue was related to the way VS Code deals with a project containing multiple ESLint working directories (common in monorepos).

For example

Project
   |--- /web
   |--- /studio

In my project root, edit (or create) ./.vscode/settings.json to include my ESLint projects. NB: these settings only apply to your current workspace.

"eslint.workingDirectories": ["./web", "./studio"]

Hope that helps :-)

Solution 2:[2]

Method 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"]
    }

Method 2:

You need to install npm with this command:

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

         or


npm install --save-dev @babel/core

I hope this will solve your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 abel