Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm: how to find the latest compatible version of a dependency for a node module at a specific version?

Is there a way to determine the latest version of a specific module which is compatible with another module at a specific version?

For example, running npm install @angular/http pulls @angular/[email protected] which dependes on rxjs@^6.0.0, but a lower version of rxjs is already present in the project — [email protected], and bumping this version will require updating a whole lot of other modules, which I want to avoid.

Is there a command that can show that the latest version of @angular/http which is compatible with [email protected] is x.y.z?

There are tools like npmvet which are good at displaying mismatched versions in the current project but can't find any tools which would show which versions can be used to resolve compatibility conflicts.

like image 402
ccpizza Avatar asked Apr 26 '20 20:04

ccpizza


People also ask

What version of npm is compatible with node?

npm code base currently uses ES6 but no higher. Latest Node 6 release covers 99% of ES6 spec, it's expected that NPM 6.2. 0 is fully workable with Node 6.14 or higher. Generally, it's certain that latest even major version (Node 10, as of now) doesn't have problems with latest NPM release.

How do I upgrade a node package to a specific version?

Use npm outdated to see Current and Latest version of all packages. Then npm i packageName@versionNumber to install specific version : example npm i [email protected] . Or npm i packageName@latest to install latest version : example npm i browser-sync@latest .

How to update node and NPM to the latest version?

However, Node and NPM can be updated separately to their latest versions, and in the rest of this article, I'll show you how. 1. Use NPM to Update Your Node Version To update Node with NPM, you will install the n package, which will be used to interactively manage node versions on your device.

How to check installed version of a package in NPM?

Note: The npm list command doesn’t only show the installed version of packages, but also their dependencies (version). For globally installed packages, you can use the npm list -g command. Installed version of a particular package

What is NPM used for in node?

The Node Package Manager (npm) is the default package management utility for Node.js packages or modules. You can use it to install and manage versions of dependencies in your projects. It’s possible to use npm to install a specific version of a package and save your project from breaking due to introducing incompatible updates.

How to update a dependency in a NodeJS project?

To update a dependency in a Node.js project you have to follow these steps: 1 Check for outdated packages 2 Update packages to a specific version or update packages to the latest major release 3 Test your updates


2 Answers

it doesn't look like a tool exists, but using npmvet and npm view in this one line command was helpful in breaking this task down for me:

npmvet -r json | jq '.[] | .name + "@" + .packageVersion' | sed -e 's/"//g' | awk '{print "echo "$0"; npm view "$0" dependencies"}'|sh | tee ../deps.txt

this has output like so:

[email protected] !
[email protected]
{
  'loose-envify': '^1.4.0',
  'object-assign': '^4.1.1',
  'react-is': '^16.8.1'
}
[email protected] !
[email protected] !
[email protected]
{ 'eve-raphael': '0.5.0' }
[email protected]
{
  'babel-runtime': '6.x',
  classnames: '2.x',
  moment: '2.x',
  'prop-types': '^15.5.8',
  'rc-trigger': '^2.2.0'
}
[email protected]

if you're like me and have got a pre-existing package.json with many dozens of packages/libs that have been allowed/required to diverge over time, you can use this output to help unpick the best matching versions until npmvet hopefully comes up green.

for example I started with this from npmvet:

enter image description here

searching through my deps.txt, I found:

[email protected]
{
  '@typescript-eslint/parser': '^3.0.0',
  'common-tags': '^1.4.0',
  dlv: '^1.1.0',
  eslint: '^6.8.0',
  'indent-string': '^4.0.0',
  'lodash.merge': '^4.6.0',
  'loglevel-colored-level-prefix': '^1.0.0',
  prettier: '^2.0.0',
  'pretty-format': '^23.0.1',
  'require-relative': '^0.8.7',
  typescript: '^3.9.3',
  'vue-eslint-parser': '~7.1.0'
}

I'm on [email protected], but [email protected] wants [email protected].

I then ran npm i [email protected] to satisfy the dependency, and npmvet is now matching for that package:

enter image description here

like image 66
user326608 Avatar answered Oct 14 '22 10:10

user326608


I've never found a good way to do this but this tool makes it a little easier: runpkg. It just allows you to browse different versions of a package from the npm registry. I like to just look at the package.json of different versions until I find one with compatible dependencies.

like image 36
rushmarrs Avatar answered Oct 14 '22 10:10

rushmarrs