Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR: undefined when installing eslint-config-airbnb #150

Open
AntoineChwat opened this issue Jun 5, 2021 · 7 comments
Open

ERR: undefined when installing eslint-config-airbnb #150

AntoineChwat opened this issue Jun 5, 2021 · 7 comments
Labels

Comments

@AntoineChwat
Copy link

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 eslint-config-airbnb@18.2.1 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: solitaire@0.1.0
56 error Found: eslint@7.28.0
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 eslint-config-airbnb@18.2.1
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 eslint-plugin-react-hooks@1.7.0
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 eslint-config-airbnb@18.2.1
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: airbnb/javascript#2436

@ljharb
Copy link
Collaborator

ljharb commented Jun 5, 2021

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 ljharb added the bug label Jun 5, 2021
@nathanhleung
Copy link
Owner

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.

@AntoineChwat
Copy link
Author

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
Copy link
Author

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

@ljharb
Copy link
Collaborator

ljharb commented Jun 7, 2021

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.

@AntoineChwat
Copy link
Author

All right so this is my attempt to fix the issue, if anything is unclear or whatever let me know
#153

@petetnt
Copy link

petetnt commented Dec 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants