PacktPublishing / Modernizing-Drupal-10-Theme-Development

Designing Modern Drupal Themes, Published by Packt
MIT License
39 stars 24 forks source link

Yarn Installs ESLint Version > 8 #52

Open aXb0t opened 7 months ago

aXb0t commented 7 months ago

In Chapter 2, Setting a New Theme and Build Process, the yarn command installs default package versions for ESLint and friends:

yarn add -D eslint eslint-config-airbnb-base eslint-config-prettier eslint-plugin-import eslint-plugin-prettier eslint-plugin-yml prettier

This currently installs ESLint version 9, which very recently made .eslintrc.json files an error condition. See https://eslint.org/blog/2023/10/flat-config-rollout-plans/

  • The ESLint CLI will search for eslint.config.js by default instead of a .eslintrc.* file.
  • If an eslint.config.js file is not found, the CLI will consider this an error and won’t run.
  • If you want to use eslintrc, you’ll need to set the ESLINT_USE_FLAT_CONFIG environment variable to false. When you do this, you’ll get a deprecation warning in the console.

Without modifiying the code to support ESLint Flat Config I was able to work around this by limiting yarn to installing ESLint 8:

yarn add -D eslint@8 eslint-config-airbnb-base eslint-config-prettier eslint-plugin-import eslint-plugin-prettier eslint-plugin-yml prettier

Also, it might be possible to set the ESLINT_USE_FLAT_CONFIG environment variable to false in DDEV. I haven't been able to verify this yet, however.

javaskater commented 1 month ago

I have a similar problem

The file ..erlintrc.json is no more use

And the new JSON file asks for modules incompatible with those already installed.

# I test the lint JS command
jpmena@packt-web:/var/www/html/web/themes/custom/alps_trips$ yarn run lint:js
yarn run v1.22.22
$ node ./node_modules/eslint/bin/eslint.js --fix .

Oops! Something went wrong! :(

ESLint: 9.13.0

ESLint couldn''t find an eslint.config.(js|mjs|cjs) file. # it does not use the old ..erlintrc.json file anymore

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
# I follow the link above and install and run the migration module
jpmena@packt-web:/var/www/html/web/themes/custom/alps_trips$ npx @eslint/migrate-config .eslintrc.json
Need to install the following packages:
@eslint/migrate-config@1.3.3
Ok to proceed? (y) y

Migrating .eslintrc.json

Wrote new config to ./eslint.config.mjs

You will need to install the following packages to use the new config:
- globals
- @eslint/js
- @eslint/eslintrc

You can install them using the following command:

npm install globals @eslint/js @eslint/eslintrc -D
# I try the command above with and without global (here without)
jpmena@packt-web:/var/www/html/web/themes/custom/alps_trips$ npm install @eslint/js @eslint/eslintrc -D
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: eslint-config-airbnb-base@15.0.0
npm error Found: eslint@9.13.0
npm error node_modules/eslint
npm error   peer eslint@">=6.0.0" from eslint-compat-utils@0.5.1
npm error   node_modules/eslint-compat-utils
npm error     eslint-compat-utils@"^0.5.0" from eslint-plugin-yml@1.14.0
npm error     node_modules/eslint-plugin-yml
npm error       dev eslint-plugin-yml@"^1.14.0" from the root project
npm error   peer eslint@">=7.0.0" from eslint-config-prettier@9.1.0
npm error   node_modules/eslint-config-prettier
npm error     peerOptional eslint-config-prettier@"*" from eslint-plugin-prettier@5.2.1
npm error     node_modules/eslint-plugin-prettier
npm error       dev eslint-plugin-prettier@"^5.2.1" from the root project
npm error     dev eslint-config-prettier@"^9.1.0" from the root project
npm error   5 more (eslint-plugin-import, eslint-plugin-prettier, ...)
npm error
npm error Could not resolve dependency:
npm error peer eslint@"^7.32.0 || ^8.2.0" from eslint-config-airbnb-base@15.0.0
npm error node_modules/eslint-config-airbnb-base
npm error   dev eslint-config-airbnb-base@"^15.0.0" from the root project
npm error
npm error Conflicting peer dependency: eslint@8.57.1
npm error node_modules/eslint
npm error   peer eslint@"^7.32.0 || ^8.2.0" from eslint-config-airbnb-base@15.0.0
npm error   node_modules/eslint-config-airbnb-base
npm error     dev eslint-config-airbnb-base@"^15.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /mnt/ddev-global-cache/npm/_logs/2024-10-29T16_05_49_014Z-eresolve-report.txt
npm error A complete log of this run can be found in: /mnt/ddev-global-cache/npm/_logs/2024-10-29T16_05_49_014Z-debug-0.log