Parsing error in `schemas` folder, potential linter issue

12 replies
Last updated: Mar 5, 2022
Wondering if anyone else has run into this — I have an error popping up only in my
schemas
folder for some reason:
Parsing error: Cannot find module '@babel/preset-env'
Not entirely sure what’s causing it, I’ve tried googling the error and making suggested changes to my various config files but so far nothing I’ve tried helps. I’m not super familiar with what’s going on behind the scenes with some of these node packages that come with Sanity so any guidance would be appreciated.

For what it’s worth, I moved this
studio
directory from a different directory, and everything seems to be working fine at least in development (data and sanity studio are working fine on localhost:3333 and in local front end), but I can’t figure out what’s causing this parsing error.
AI Update

This is typically a VSCode/ESLint configuration issue rather than a Sanity-specific problem. Since your studio is working fine in development and the error only appears in your editor, it's a tooling issue with how ESLint is trying to parse your files.

First, identify what's actually causing the error:

The error message suggests ESLint is trying to use Babel to parse your schema files but can't find the necessary dependencies. Before installing anything, check what ESLint configuration you're actually using:

  1. Look in your package.json for any eslint-config-* packages
  2. Check your .eslintrc (or .eslintrc.json, .eslintrc.js) file to see what you're extending

Common solutions to try:

1. VSCode ESLint working directory issue (especially relevant since you moved directories)

If you're in a monorepo or moved your studio folder, VSCode's ESLint extension might be looking for dependencies in the wrong place. Add this to your .vscode/settings.json in your studio directory:

{
  "eslint.workingDirectories": [
    { "mode": "auto" }
  ]
}

Or specify the studio directory explicitly if it's nested:

{
  "eslint.workingDirectories": [
    "./studio"
  ]
}

2. Clear caches and reinstall

Since you moved the directory, stale references might be causing issues:

rm -rf node_modules package-lock.json
npm install

Then restart VSCode completely.

3. Install the missing dependencies only if you confirm they're needed

Only do this if your ESLint config explicitly requires Babel parsing. Check your .eslintrc for parser: '@babel/eslint-parser' or similar. If it's there:

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

4. Disable ESLint for schemas if it's not adding value

If you don't need linting on your schema files (they're mostly configuration), you can tell ESLint to skip them. Add to your .eslintrc.json:

{
  "ignorePatterns": ["schemas/"]
}

5. Reload the ESLint server in VSCode

Open the command palette (Cmd/Ctrl + Shift + P) and run "ESLint: Restart ESLint Server"

The key here is that this is an editor/linting configuration issue, not a Sanity problem. Since everything works in development, you're not blocked from building or deploying. The most likely culprit is VSCode's ESLint extension looking for dependencies in the wrong location after you moved the directory, which the workingDirectories setting should resolve.

I can confirm the module is definitely in there
looks like this. maybe I’m missing something?
It doesn't look like anything there is causing it. Do you have a
.babelrc
or
babel.config.json
in your project?
I don’t think so, that wouldn’t go in the
node_modules
right?
No, it would have been something you set up in the root of your Studio. Hmm, I'll keep exploring.
No, it would have been something you set up in the root of your Studio. Hmm, I'll keep exploring.
Was there a resolution to this?I am having the same issue, clean install of Sanity from the cli.
So far I haven't found any — I can check again later today if the issue is still happening but so far it hasn't prevented anything from working. Could be a linter issue?
I’m having this issue too on a clean install from CLI v2.27.0. At this stage, it seems limited to a linter issue. Did anyone find a solution?
If others are still having this issue, my fix was related to the way VS Code deals with opening a project with multiple sub projects
Project
|--- /web
If others are still having this issue, my fix was related to the way VS Code deals with opening a project with multiple sub projects
Project
|--- /web
If others are having this error, my 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
Edit`./.vscode/settings.json` to include my ESLint projects
"eslint.workingDirectories": ["./web", "./studio"]
.
Hope that helps :-)

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?