yarn icon indicating copy to clipboard operation
yarn copied to clipboard

ESLint Error: when installed with yarn

Open anjantalatam opened this issue 2 years ago • 4 comments

yarn version: 1.22.19

Bug: ESLint is throwing the below error when yarn run lint is executed given ESLint is installed with yarn.

package.json

  "scripts": {
    "lint": "eslint src",
  }

Complete error:

There was a problem loading formatter: <path_to_node_project>/node_modules/eslint/lib/cli-engine/formatters/stylish
Error: require() of ES Module <path_to_node_project>/node_modules/strip-ansi/index.js from <path_to_node_project>/api/node_modules/eslint/lib/cli-engine/formatters/stylish.js not supported.
Instead change the require of index.js in <path_to_node_project>/node_modules/eslint/lib/cli-engine/formatters/stylish.js to a dynamic import() which is available in all CommonJS modules.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Here is a discussion from eslint https://github.com/eslint/eslint/discussions/17215#discussioncomment-5983847

yarn run lint working fine when ESLint is installed with npm or pnpm

anjantalatam avatar Aug 17 '23 12:08 anjantalatam

Will be fix this problem? Can't setting project with eslint using yarn... It makes me sad 😢

baryman avatar Sep 16 '23 12:09 baryman

It works with newer versions of yarn. IMHO it's unlikely this will be fixed because it's not a security issue. The yarn upgrade is easy and you get a whole bunch of features and performance improvements.

ArloL avatar Sep 16 '23 19:09 ArloL

Removing yarn.lock and reinstalling packages with yarn install can fix the problem. But it can occur again (for instance, when changing git branches).

UPD from eslint discussion: can be fixed by downgrading strip-ansi version in package.json by adding:

 "resolutions": {
    "strip-ansi": "^6.0.1"
}

vozmi avatar Sep 20 '23 16:09 vozmi

Reproduction case: https://github.com/eslint/eslint/discussions/17215#discussioncomment-8075610

isaacs avatar Jan 10 '24 05:01 isaacs