Back to all reviewers

Pin dependency versions

snyk/cli
Based on 6 comments
Json

Always pin dependencies to exact versions in package.json instead of using semantic version ranges (^, ~) to ensure reproducible builds and prevent unintentional version drift during deployments.

Configurations Json

Reviewer Prompt

Always pin dependencies to exact versions in package.json instead of using semantic version ranges (^, ~) to ensure reproducible builds and prevent unintentional version drift during deployments.

This practice is especially critical for applications deployed as units, where consistency across all dependency versions is essential. Using exact versions prevents scenarios where different environments might resolve to different dependency versions, leading to inconsistent behavior.

Use npm’s --save-exact flag when installing dependencies:

# Instead of: npm install some-package
npm install some-package --save-exact

# Or use the shorthand:
npm install some-package -E

This will add the dependency to package.json without version range operators:

{
  "dependencies": {
    "snyk-gradle-plugin": "4.1.0",  //  Exact version
    "snyk-cpp-plugin": "2.24.0"     //  Exact version
  }
}

Rather than:

{
  "dependencies": {
    "snyk-gradle-plugin": "^4.1.0",  //  Range allows 4.x.x
    "snyk-cpp-plugin": "^2.24.0"     //  Range allows 2.x.x
  }
}

While package-lock.json provides some protection against version drift, pinning to exact versions in package.json provides an additional layer of certainty and makes dependency management intentions explicit to all team members.

6
Comments Analyzed
Json
Primary Language
Configurations
Category

Source Discussions