Home > Software design >  Error: .eslintrc.json: Configuration for rule "import/no-unresolved" is invalid and should
Error: .eslintrc.json: Configuration for rule "import/no-unresolved" is invalid and should

Time:10-19

After implement eslint and prettier together without conflicts, babel is added correctly.

I am trying to add absolute paths in TypeScript using the plugin "eslint-plugin-module-resolver", everything fine to compile, transpile or start a server, but I am still getting an error just in eslint only.

Error description - Should NOT have additional properties while "npm run lint".

Can someone help me with this issue?! Thanks

Error #1

npm run lint

> [email protected] lint
> eslint . --ext .ts .tsx


Oops! Something went wrong! :(

ESLint: 8.25.0

Error: .eslintrc.json:
        Configuration for rule "import/no-unresolved" is invalid:
        Value {"plugins":["module-resolver/use-alias",{"alias":{"@config":"./src/config","@controllers":"./src/controllers","@services":"./src/services","@models":"./src/models","@routes":"./src/routes","@pages":"./src/pages","@utils":"./src/utils","@middlewares":"./src/middlewares"}}],"caseSensitive":true,"caseSensitiveStrict":false} should NOT have additional properties.

.eslintrc.json

{
      "env": {
        "es2021": true,
        "node": true
      },
      "extends": [
        "eslint:recommended",
        "plugin:prettier/recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier"
      ],
      "overrides": [],
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module",
        "project": "./tsconfig.json"
      },
      "plugins": ["@typescript-eslint", "module-resolver", "prettier", "import"],
      "rules": {
        "indent": ["error", 2],
        "tabwidth": ["error", 2],
        "linebreak-style": ["error", "unix"],
        "quotes": ["error", "double"],
        "semi": ["error", "always"],
        "trailingComma": ["warn", "none"],
        "prettier/prettier": "error",
        "import/no-unresolved": [
          "error",
          {
            "plugins": [
              "module-resolver",
              {
                "alias": {
                  "@config": "./src/config",
                  "@controllers": "./src/controllers",
                  "@services": "./src/services",
                  "@models": "./src/models",
                  "@routes": "./src/routes",
                  "@pages": "./src/pages",
                  "@utils": "./src/utils",
                  "@middlewares": "./src/middlewares"
                }
              }
            ]
          }
        ]
      }
    }

package.json

{
  "name": "setup",
  "version": "1.0.0",
  "description": "Nodejs setup using typescript, babel, eslint and prettier",
  "main": "index.js",
  "author": "Gonzalo Cugiani",
  "license": "MIT",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "ts-node-dev -r tsconfig-paths/register --respawn src/index.ts",
    "build": "babel src --extensions \".ts, .js\" --out-dir dist --copy-files",
    "start": "node dist/index.js",
    "lint": "eslint . --ext .ts .tsx"
  },
  "devDependencies": {
    "@babel/cli": "^7.19.3",
    "@babel/core": "^7.19.3",
    "@babel/node": "^7.19.1",
    "@babel/preset-env": "^7.19.4",
    "@babel/preset-typescript": "^7.18.6",
    "@types/express": "^4.17.14",
    "@typescript-eslint/eslint-plugin": "^5.40.1",
    "@typescript-eslint/parser": "^5.40.1",
    "babel-plugin-module-resolver": "^4.1.0",
    "eslint": "^8.25.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-module-resolver": "^1.5.0",
    "eslint-plugin-prettier": "^4.2.1",
    "prettier": "^2.7.1",
    "ts-node-dev": "^2.0.0",
    "tsconfig-paths": "^4.1.0",
    "typescript": "^4.8.4"
  },
  "keywords": [],
  "dependencies": {
    "express": "^4.18.2"
  },
  "babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "targets": {
            "node": "current"
          }
        }
      ],
      "@babel/preset-typescript"
    ],
    "plugins": [
      [
        "module-resolver",
        {
          "alias": {
            "@config": "./src/config",
            "@controllers": "./src/controllers",
            "@services": "./src/services",
            "@models": "./src/models",
            "@routes": "./src/routes",
            "@pages": "./src/pages",
            "@utils": "./src/utils",
            "@middlewares": "./src/middlewares"
          }
        }
      ]
    ]
  }
}

CodePudding user response:

In .eslintrc.json, remove 2nd object argument

        "import/no-unresolved": [
          "error",
          /* remove this object -> */ {
            "plugins": [
              "module-resolver",
              {
                "alias": {
                  "@config": "./src/config",
                  "@controllers": "./src/controllers",
                  "@services": "./src/services",
                  "@models": "./src/models",
                  "@routes": "./src/routes",
                  "@pages": "./src/pages",
                  "@utils": "./src/utils",
                  "@middlewares": "./src/middlewares"
                }
              }
            ]
          }

from "import/no-unresolved" arguments, as error says it should not be there Generally, the eslint plugin should be able to find this data in tsconfig.json or pachage.json, so it's not needed in eslintrc at all

  • Related