The npm community forum has been discontinued.
To discuss usage of npm, visit the GitHub Support Community.
How do I prefer an older version of a dependency, but allow a newer one if it's already installed?
I have an NPM package that depends on cheerio. Cheerio 0.22.0 has a 1 MB install size (according to Package Phobia) while 1.0.0-rc1 is 2.68 MB. For that reason, if whoever depends on my package does not already have cheerio ^1.0.0-rc1 in their dependency tree, I would like NPM to install cheerio ^0.22.0. If they do have ^1.0.0-rc1, I would like to use that.
Is this possible? I’ve tried depending on:
"cheerio": "^0.22.0||^1.0.0-rc1" and
"cheerio": "^1.0.0-rc1||^0.22.0" but both install ^1.0.0-rc1 if cheerio is not already installed.
The latest version compatible version will be installed if an install is needed.
You can experiment in the npm semver calculator