yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.37k stars 2.72k forks source link

ESLint Error: when installed with yarn #8976

Open anjantalatam opened 10 months ago

anjantalatam commented 10 months ago

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

baryman commented 9 months ago

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

ArloL commented 9 months ago

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.

vozmi commented 9 months ago

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"
}
isaacs commented 5 months ago

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