update-package
raw JSON → 0.2.0 verified Fri May 01 auth: no javascript abandoned
A Node.js library (v0.2.0, last updated February 2015) for updating or linting a package.json file against a set of defaults. Originally designed to enforce consistent fields across multiple projects, it appears to read a template/defaults object and merge it into an existing package.json. The package is minimal, using only Node's built-in fs and path modules, and has no significant external dependencies. Its development cadence is very low (single release), and it has been largely superseded by more active tools like sort-package-json or npm-check. The project is now archived/unmaintained.
Common errors
error Error: Cannot find module 'update-package' ↓
cause Package not installed or npm install failed.
fix
Run 'npm install update-package'
error TypeError: updatePkg is not a function ↓
cause Using ES6 import syntax with CJS package.
fix
Use 'const updatePkg = require('update-package')' instead of 'import updatePkg from ...'.
error TypeError: Cannot read property 'name' of undefined ↓
cause Missing or invalid defaults object as first argument.
fix
Ensure first argument is an object with required fields.
Warnings
deprecated Package is unmaintained since 2015. Use modern alternatives like sort-package-json or npm init. ↓
fix Use sort-package-json or migrate to npm's built-in defaults.
gotcha The function mutates the first argument (defaults) and returns it; does not create a deep copy. ↓
fix Pass a shallow copy of defaults: updatePkg({...defaults}, pkg)
gotcha Only works with CommonJS require; not ESM compatible and no dual build. ↓
fix Use dynamic import or rewrite to use require.
deprecated No longer maintained; known issues with npm v2+ and newer Node versions may cause unexpected behavior. ↓
fix Switch to a maintained alternative.
Install
npm install update-package yarn add update-package pnpm add update-package Imports
- default wrong
import updatePkg from 'update-package'correctconst updatePkg = require('update-package') - none (callable) wrong
const updatePkg = new (require('update-package'))(defaults, pkg)correctconst updatePkg = require('update-package')(defaults, pkg) - none (type)
const updatePkg = require('update-package')
Quickstart
const updatePkg = require('update-package');
const defaults = { name: 'my-app', version: '1.0.0' };
const pkg = { name: 'my-app', version: '0.9.0', private: true };
const result = updatePkg(defaults, pkg);
console.log(result);
// { name: 'my-app', version: '1.0.0', private: true }