0

I am developing a REST API backend with express and I need to import some JSON local files, so I used the experimental assert { type: "json" } syntax.

ESLint still doesn't support it, the solution is to use babel parser for ESLint.

I added as dev dependencies:

"@babel/core": "^7.22.1",
"@babel/eslint-parser": "^7.21.8",
"@babel/plugin-syntax-import-assertions": "^7.20.0"

I added in .eslintconfi.json:

"parser": "@babel/eslint-parser",
  "parserOptions": {
    "requireConfigFile": false,
    "babelOptions": {
      "plugins": [
        "@babel/plugin-syntax-import-assertions"
      ]
    }
  },

The linting works just fine but VScode gives me Parsing error: Cannot find module '@babel/plugin-syntax-import-assertions error on every file:

error

Favo02
  • 48
  • 1
  • 5

1 Answers1

0

The problem was opening multiple folders with eslint in the same workspace, both frontend and backend in my case. Opening only the backend the issue disappears.

To open both folders in the same workspace edit workspace settings (.vscode/settings.json file), adding:
{ "eslint.workingDirectories": ["frontend", "backend"] }

More here

Favo02
  • 48
  • 1
  • 5