'npm equivalent of yarn install --check-files (or yarn check)

Update for 2020

This question originally referred to the yarn check command, but the docs state that this is deprecated in v1, and removed in v2, and yarn install --check-files should be used instead.

Unfortunately there is still, apparently, no equivalent of the --check-files flag in npm install!


As part of my development build I'd like to check that the versions of dependencies in node_modules are what's expected to be there according to both what's specified in package.json and the lockfile package-lock.json.

In yarn you can do this with yarn install --check-files (or the older deprecated yarn check command in v1)

I am trying to achieve the same using npm.

At the moment I am using npm ci (see docs here) which does work, in the sense that it completely reinstalls node_modules from what's in the lockfile and then errors if the versions in package.json don't match.

But, this is a bit heavyweight and slow. I'm wondering if there is a purely static way to run these checks with npm that doesn't involve cleaning and reinstalling everything on disk?



Solution 1:[1]

I believe npm prune (docs) is what you are looking for.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anders