Home > Enterprise >  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser for gats
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser for gats

Time:05-01

I've read a lot of posts with this same error message but all of them are regarding their .eslintrc or babel config file. I'm using the gatsby/typescript starter kit from their website here: https://www.gatsbyjs.com/starters/jpedroschmitz/gatsby-starter-ts

The problem is, when I create a server/index.ts file from the root, since its outside the src folder, on the first line of the file, I get: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: server/index.ts. The file must be included in at least one of the projects provided. I have the exact same set up as in the the starter kit and i tried including the server folder in tsconfig but with no luck.

tsconfig.json:
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
      "@/static/*": ["./static/*"]
    }
  },
  "exclude": ["node_modules"],
  "include": ["./src/**/*", "./__helpers__/*"]
}

.eslintrc
{
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "plugins": ["react", "react-hooks", "jsx-a11y", "prettier", "jest"],
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "prettier",
    "plugin:jest/recommended",
    "plugin:jest/style"
  ],
  "rules": {
    "jest/prefer-strict-equal": "error",
    "jest/prefer-to-have-length": "warn",
    "prettier/prettier": "error",
    "import/prefer-default-export": "off",
    "react/prop-types": "off",
    "react/jsx-filename-extension": "off",
    "react/jsx-props-no-spreading": "off",
    "import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": [
          "**/*.test.[jt]s",
          "**/*.spec.[jt]s",
          "**/*.test.[jt]sx",
          "**/*.spec.[jt]sx"
        ]
      }
    ],
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "ts": "never",
        "tsx": "never",
        "js": "never",
        "jsx": "never"
      }
    ],
    "react/function-component-definition": [
      2,
      {
        "namedComponents": "function-declaration"
      }
    ]
  },
  "overrides": [
    {
      "files": "**/*. (ts|tsx)",
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "project": "./tsconfig.json"
      },
      "plugins": ["@typescript-eslint/eslint-plugin"],
      "extends": [
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier"
      ],
      "rules": {
        "@typescript-eslint/explicit-function-return-type": "off",
        "@typescript-eslint/no-explicit-any": "off",
        "@typescript-eslint/no-var-requires": "off",
        "no-use-before-define": [0],
        "@typescript-eslint/no-use-before-define": [1],
        "import/no-unresolved": 0,
        "import/no-extraneous-dependencies": [
          "error",
          {
            "devDependencies": [
              "**/*.test.ts",
              "**/*.spec.ts",
              "**/*.test.tsx",
              "**/*.spec.tsx"
            ]
          }
        ],
        "quotes": "off",
        "@typescript-eslint/quotes": [
          2,
          "backtick",
          {
            "avoidEscape": true
          }
        ],
        "@typescript-eslint/no-unused-vars": [2, { "argsIgnorePattern": "^_" }]
      }
    }
  ],
  "settings": {
    "import/resolver": {
      "typescript": {
        "project": "."
      }
    },
    "react": {
      "version": "detect"
    }
  }
}

server/index.ts:
import express, { Express, Request, Response } from 'express';
import cors from 'cors';

const app: Express = express();
const port = 3000;

app.use(cors());
app.use(express.json());

app.get('/', (req: Request, res: Response) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

CodePudding user response:

In your tsconfig.json file you need to add your server folder to include:

"include": ["./src/**/*", "./__helpers__/*", "server/**/*" ]
  • Related