install-peerdeps icon indicating copy to clipboard operation
install-peerdeps copied to clipboard

ERR: undefined when installing eslint-config-airbnb

Open AntoineChwat opened this issue 3 years ago • 7 comments

When running npx install-peerdeps --dev eslint-config-airbnb I get the following error:

install-peerdeps v3.0.3
Installing peerdeps for eslint-config-airbnb@latest.
npm install [email protected] eslint@^7.2.0 eslint-plugin-import@^2.22.1 eslint-plugin-jsx-a11y@^6.4.1 eslint-plugin-react@^7.21.5 eslint-plugin-react-hooks@^1.7.0 --save-dev

ERR undefined

Digging a bit more, I found the following log in my ~/.npm/_logs/ folder:

51 verbose node v16.1.0
52 verbose npm  v7.16.0
53 error code ERESOLVE
54 error ERESOLVE unable to resolve dependency tree
55 error
56 error While resolving: [email protected]
56 error Found: [email protected]
56 error node_modules/eslint
56 error   dev eslint@"^7.2.0" from the root project
56 error   peer eslint@"^5.16.0 || ^6.8.0 || ^7.2.0" from [email protected]
56 error   node_modules/eslint-config-airbnb
56 error     dev eslint-config-airbnb@"18.2.1" from the root project
56 error   3 more (eslint-plugin-import, eslint-plugin-jsx-a11y, eslint-plugin-react)
56 error
56 error Could not resolve dependency:
56 error peer eslint@"^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0" from [email protected]
56 error node_modules/eslint-plugin-react-hooks
56 error   dev eslint-plugin-react-hooks@"^1.7.0" from the root project
56 error   peer eslint-plugin-react-hooks@"^4 || ^3 || ^2.3.0 || ^1.7.0" from [email protected]
56 error   node_modules/eslint-config-airbnb
56 error     dev eslint-config-airbnb@"18.2.1" from the root project
56 error
56 error Fix the upstream dependency conflict, or retry
56 error this command with --force, or --legacy-peer-deps
56 error to accept an incorrect (and potentially broken) dependency resolution.
56 error

To me, it seems like install-peerdeps does not retrieve the correct version of eslint-plugin-react-hooks - instead of getting the latest 4.x version, it gets the 1.7.0 version, which indeed does not support eslint 7.x

Bug has already been reported to eslint-config-airbnb here: https://github.com/airbnb/javascript/issues/2436

AntoineChwat avatar Jun 05 '21 22:06 AntoineChwat

In other words, it should be grabbing the semver-latest from "^4 || ^3 || ^2.3.0 || ^1.7.0", but instead it's grabbing the "last" item.

ljharb avatar Jun 05 '21 22:06 ljharb

Thanks for this report! Right now the behavior is to grab the last item in the range:

// Semver ranges can have a join of comparator sets
// e.g. '^3.0.2 || ^4.0.0' or '>=1.2.7 <1.3.0'
// Take the last version in the range
const rangeSplit = version.split(" ");
const versionToInstall = rangeSplit[rangeSplit.length - 1];

(from https://github.com/nathanhleung/install-peerdeps/blob/master/src/install-peerdeps.js#L159)

It should be a few-line change to use semver's sort function to sort the rangeSplit array and grab the latest version – code would look similar to below:

const semverSort = require('semver/functions/sort');

// ...

const sortedRangeSplit = semverSort(rangeSplit);
const versionToInstall = sortedRangeSplit.pop();

If you are willing to take this change on + add some tests to verify it works, this can be a great first PR! Otherwise, I can look into this later this week.

nathanhleung avatar Jun 07 '21 14:06 nathanhleung

Ah so that's where the issue is, all right well it doesn't look very complex, I'll try to give it a go this week then

AntoineChwat avatar Jun 07 '21 15:06 AntoineChwat

Okay so I looked more into it and there are several issues:

  • First off it looks like this plugin does not support ranges written as for instance >=5.0.0. Is that normal, or did I get that wrong? And if it's not normal is that something we should handle?
  • I can't use semverSort since we are not dealing with versions directly but with ranges, which incidentally means that for instance "^5.0.0" actually goes higher than "~5.1.0" (I'm hoping no one is stupid enough to write both of these in their peer dependencies but eh, you never know) so it is quite a pain I'll keep thinking about an elegant solution to this sorting problem on my end, if you have any ideas feel free to shoot a message

AntoineChwat avatar Jun 07 '21 19:06 AntoineChwat

I think anything valid should be supported; the semver library works fine for that (stick to v6 for maximum back compat)

it has a Range object and a bunch of useful methods.

ljharb avatar Jun 07 '21 22:06 ljharb

All right so this is my attempt to fix the issue, if anything is unclear or whatever let me know https://github.com/nathanhleung/install-peerdeps/pull/153

AntoineChwat avatar Jun 08 '21 14:06 AntoineChwat

Still had the same issue with ERR undefined when running install-peerdeps with a command pointing to verdaccio registry, I worked around the issue by running the command in two steps:

$PKG=package-name-here
$LOCAL_REGISTRY=https://my-local-registry.me

npx install-peerdeps --only-peers $PKG --registry $LOCAL_REGISTRY
npm install $PKG --registry $LOCAL_REGISTRY

Not sure why it fails with undefined even though --dry-run seems to get the correct versions of all the packages.

petetnt avatar Dec 07 '23 11:12 petetnt