Update all dependency versions in package.json to be exact version currently installed.
Last updated 3 years ago by camachgk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install exact-deps 
SYNC missed versions from official npm registry.


Update package.json to use exact versions for dependencies

NOTE: this does not replace the best practice of adding a .npmrc file with save-exact=true attribute to a project

yarn add -D exact-deps
<summary>Table of Contents</summary>

Getting started

For a variety of reasons, I have often wanted to convert all the versions of dependencies in a package.json file to the exact versions that have been installed.

exact-deps solves this problem by

  • looping through each dependency in the main package.json file
  • for each dependency:
    • finding the locally installed dependency's package.json file
    • updating the entry in the main package.json with the version attribute from the dependency's package.json file


  • node: >=8

Command Line

This module provides a simple CLI:


If combined with Yarn, it can be run as:

yarn exact-deps package.json

It can also be used as part of an npm script:

  "scripts": {
    "deps:exact": "exact-deps"
  "devDependencies": {
    "exact-deps": "latest"
yarn deps:exact


Option Alias Description Default
prefix p Prefix to put before each version ''
help h Print help menu


The module exports a function that takes the directory of package.json and a prefix.

It returns a new object with path and contents properties

const fs = require('fs');
const exactDeps = require('exact-deps');

const { path, contents } = exactDeps(process.cwd(), '^');
fs.writeFileSync(path, JSON.stringify(contents, null, 2));


An effective integration of this plugin could look like this:

  "scripts": {
    "deps:exact": "exact-deps",
    "precommit": "lint-staged",
    "prepublish": "deps:exact"
  "lint-staged": {
    "package.json": [
      "exact-deps -p ^",
      "git add"
  "devDependencies": {
    "lint-staged": "latest",
    "exact-deps": "latest"
  "optionalDependencies": {
    "husky": "latest"

This configuration combines:

  • lint-staged for automatically running tasks on staged files
  • husky for githook integrations
  • exact-deps to make sure package.json is always exact

Together, these modules ensure the package.json file is automatically updated if it changes and provides an easy package.json script for manual use:

yarn deps:exact

Current Tags

  • 1.2.1                                ...           latest (3 years ago)

4 Versions

  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |