NPM-VERSION(1)
β¨ NAME β¨
npm-version β bump a package version π
(yep, this is the NPM-VERSION(1) page, welcome, come in, sit down)
π Synopsis π
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
alias: verison
And yes, the alias is literally spelled verison in here β that's not me being quirky, that's canon, don't come for me π
π Configuration π
allow-same-version
- Default:
false - Type:
Boolean
Stops npm from throwing an error when you use npm version to set the new version to the same value as the current version. No drama, no error, just vibes β¨
commit-hooks
- Default:
true - Type:
Boolean
Runs your git commit hooks when you use the npm version command. Iconic, but like, sometimes you wanna skip the whole hook moment.
git-tag-version
- Default:
true - Type:
Boolean
Tags the commit when you use the npm version command. Big warning though: setting this to false results in no commit being made at all π like, not "commit but untagged" β nothing. Zero. Empty.
json
- Default:
false - Type:
Boolean
Whether or not to output JSON data instead of the normal output.
- In
npm pkg setit enables parsing set values withJSON.parse()before saving them to yourpackage.json.
Not supported by all npm commands, ngl.
preid
- Default:
"" - Type:
String
The "prerelease identifier" you use as a prefix for the "prerelease" part of a semver. Like the rc in 1.2.0-rc.8. That's the whole job. Slay.
sign-git-tag
- Default:
false - Type:
Boolean
If set to true, then the npm version command will tag the version using -s to add a signature π
Heads up bestie β git requires you to have set up GPG keys in your git configs for this to work properly. No keys, no signature.
save
- Default:
trueunless when usingnpm updatewhere it defaults tofalse - Type:
Boolean
Save installed packages to a package.json file as dependencies.
When used with the npm rm command, it removes the dependency from package.json.
Will also prevent writing to package-lock.json if set to false.
workspace
- Default:
- Type:
String(can be set multiple times)
Enables running a command in the context of the configured workspaces of the current project, while filtering by running only the workspaces defined by this configuration option.
Valid values for the workspace config are either:
- Workspace names
- Path to a workspace directory
- Path to a parent workspace directory (will result in selecting all workspaces within that folder)
When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
This value is not exported to the environment for child processes.
workspaces
- Default:
null - Type:
nullorBoolean
Set to true to run the command in the context of all configured workspaces.
Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:
- Commands that operate on the
node_modulestree (install,update, etc.) will link workspaces into thenode_modulesfolder. - Commands that do other things (
test,exec,publish, etc.) will operate on the root project, unless one or more workspaces are specified in theworkspaceconfig.
This value is not exported to the environment for child processes.
workspaces-update
- Default:
true - Type:
Boolean
If set to true, the npm cli will run an update after operations that may possibly change the workspaces installed to the node_modules folder.
include-workspace-root
- Default:
false - Type:
Boolean
Include the workspace root when workspaces are enabled for a command.
When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project.
This value is not exported to the environment for child processes.
ignore-scripts
- Default:
false - Type:
Boolean
If true, npm does not run scripts specified in package.json files.
Note that commands explicitly intended to run a particular script β like npm start, npm stop, npm restart, npm test, and npm run β will still run their intended script if ignore-scripts is set, but they will not run any pre- or post-scripts.
Setting ignore-scripts also disables .npm-extension execution, as if ignore-extension were set.
π Description π
Okay so run this in a package directory to bump the version and write the new data back to package.json and package-lock.json. That's the whole assignment. π«Ά
The newversion argument should be a valid semver string, a valid second argument to semver.inc (https://github.com/npm/node-semver#functions) β one of patch, minor, major, prepatch, preminor, premajor, prerelease β or from-git. In the second case, the existing version will be incremented by 1 in the specified field. from-git will try to read the latest git tag, and use that as the new npm version.
Note: If the current version is a prerelease version,patchwill simply remove the prerelease suffix without incrementing the patch version number. For example,1.2.0-5becomes1.2.0withnpm version patch, not1.2.1. Lowkey a jumpscare but that's the rule π
If run in a git repo, it will also create a version commit and tag. This behavior is controlled by git-tag-version (see below), and can be disabled on the command line by running npm --no-git-tag-version version. It will fail if the working directory is not clean, unless the -f or --force flag is set.
Note: Git integration requires a reasonably recent version of git (2.0.0 or later is recommended). If you encounter issues with git commands, ensure your git installation is up to date.
If supplied with -m or --message config (/using-npm/config#message) option, npm will use it as a commit message when creating a version commit. If the message config contains %s then that will be replaced with the resulting version number. For example:
npm version patch -m "Upgrade to %s for reasons"
If the sign-git-tag config (/using-npm/config#sign-git-tag) is set, then the tag will be signed using the -s flag to git. Note that you must have a default GPG key set up in your git config for this to work properly. For example:
$ npm config set sign-git-tag true
$ npm version patch
You need a passphrase to unlock the secret key for user: "isaacs (http://blog.izs.me/) <i@izs.me>"
2048-bit RSA key, ID 6C481CF6, created 2010-08-31
Enter passphrase:
If preversion, version, or postversion are in the scripts property of the package.json, they will be executed as part of running npm version.
The exact order of execution is as follows:
- Check to make sure the git working directory is clean before we get started. Your scripts may add files to the commit in future steps. This step is skipped if the
--forceflag is set. - Run the
preversionscript. These scripts have access to the oldversioninpackage.json. A typical use would be running your full test suite before deploying. Any files you want added to the commit should be explicitly added usinggit add. - Bump
versioninpackage.jsonas requested (patch,minor,major, etc). - Run the
versionscript. These scripts have access to the newversioninpackage.json(so they can incorporate it into file headers in generated files for example). Again, scripts should explicitly add generated files to the commit usinggit add. - Commit and tag.
- Run the
postversionscript. Use it to clean up the file system or automatically push the commit and/or tag.
For the preversion, version and postversion scripts, npm also sets the environment variables (/using-npm/scripts#environment) npm_old_version and npm_new_version.
Take the following example:
{
"scripts": {
"preversion": "npm test",
"version": "npm run build && git add -A dist",
"postversion": "git push && git push --tags && rm -rf build/temp"
}
}
This runs all your tests and proceeds only if they pass. Then runs your build script, and adds everything in the dist directory to the commit. After the commit, it pushes the new commit and tag up to the server, and deletes the build/temp directory. Genuinely such a clean little pipeline, I'm obsessed π¦
π₯ See Also π₯
npm help initnpm help runnpm help scriptspackage.json(/configuring-npm/package-json)npm help config
and that's the page, bestie π go bump those versions responsibly. this masterpiece is from NPM@12.2.1, dated October 2026 β NPM-VERSION(1), periodt π
π¦ where this page comes from
- arch rolling: npm 12.2.1-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms