Search code examples
eslintnrwl-nxtypescript-eslint

Lint rule "no-restricted-imports" throw error when patterns group specified


I configured .eslintrc.json in Nx/nrwl monorepo for React project. When I add group to pattern attribute to no-restricted-import

"rules": {
    "no-restricted-imports": [
      "error",
      {
        "patterns": [
          {
            "group": ["lodash/*"],
            "message": "Message"
          }
        ]
      }
    ]
  }

Eslint shows error

Configuration for rule "no-restricted-imports" is invalid: Value {"patterns":[{"group":["lodash/"],"message":"Message"}]} should be string.
Value {"patterns":[{"group":["lodash/
"],"message":"Message"}]} should NOT have additional properties.

without group it works correct.

I mirrored same code shown in documentation here

/*eslint no-restricted-imports: ["error", { patterns: [{
    group: ["lodash/*"],
    message: "Please use the default import from 'lodash' instead."
}]}]*/

import pick from 'lodash/pick';

lint-error


Solution

  • I had the same problem using eslint in an nx/nrwl monorepo. Updating eslint to 7.32.0 resolved the issue for me.

    Apparently this was due to a bug in eslint that has since been fixed.

    When Nx generated my package.json, it locked down the eslint version to 7.22.0; I had to update the dependency in my package.json to ^7.22.0 and then run npm update eslint to get the latest version.