Skip to content

npm-pin-versions

Dockerfilesuspiciousno fixdefault: offdockerfile/hadolint

Reports an npm install (also npm i and npm add) of a package without a version: express instead of express@4.18.2, @scope/name instead of @scope/name@1.2.0. A path, a tarball (.tgz, .tar.gz) or a git URL with a #ref counts as pinned. The value of --loglevel or --registry is not taken for a package, and an npm install with no package (it reads package.json) is not reported.

Without a version npm installs the latest release on the day of the build, so a new major version of the package can break the image and two builds of one Dockerfile differ.

Pin the version in the command, or keep it in package.json with a lock file and use npm ci.

Reported
...
RUN pip install git+https://github.com/a/b@v1
RUN npm install
RUN npm install express
RUN npm install express@4 @scope/pkg@1
RUN npm install --loglevel verbose express@4
RUN npm install ./local
RUN npm i express
RUN npm add express@4
...
dockerfile:
lint:
rules:
npm-pin-versions: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line npm-pin-versions in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
hadolint DL3016 partial A package is judged by its text (@, #, tarball, path); git and scoped forms follow hadolint’s cases only.