ESLint Error: when installed with yarn
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
Will be fix this problem? Can't setting project with eslint using yarn... It makes me sad 😢
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.
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"
}
Reproduction case: https://github.com/eslint/eslint/discussions/17215#discussioncomment-8075610