What package version does @next specify for npm?

JavascriptNpmNpm InstallSemantic Versioning

Javascript Problem Overview


What version of package foo will this command install?

npm install foo@next

The package.json and semver docs don't mention next.

Javascript Solutions


Solution 1 - Javascript

next is a version or tag published in your reference npm registry

npm install installs a package.

A package is:

...
d) a <name>@<version> that is published on the registry (see npm-registry) with (c)
e) a <name>@<tag> (see npm-dist-tag) that points to (d)
...

You can view the version that each dist-tag points to by running the following commands:

npm view <package_name> dist-tags
npm dist-tags ls <package_name>

e.g. for the react npm package:

npm view react dist-tags

Output:

{
  latest: '17.0.2',
  next: '18.0.0-rc.0-next-3dc41d8a2-20211223',
  experimental: '0.0.0-experimental-3dc41d8a2-20211223',
  beta: '18.0.0-beta-24dd07bd2-20211208',
  rc: '18.0.0-rc.0'
}

Source

Solution 2 - Javascript

Next is tag. look at the below possible commands.

> A tag can be used when installing packages as a reference to a version instead of using a specific version number:

npm install [<@scope>/]<name>
npm install [<@scope>/]<name>@<tag>
npm install [<@scope>/]<name>@<version>
npm install [<@scope>/]<name>@<version range>

How its added in package? See dist-tag

npm dist-tag add <pkg>@<version> [<tag>]
npm dist-tag rm <pkg> <tag>
npm dist-tag ls [<pkg>]

Check - https://docs.npmjs.com/cli/dist-tag

Solution 3 - Javascript

Appending the @next tag to the package name installs the upcoming version, which is likely unstable.

From npm docs for npm-dist-tag:

> Tags can be used to provide an alias instead of version numbers. > > For example, a project might choose to have multiple streams of > development and use a different tag for each stream, e.g., stable, > beta, dev, canary. > > By default, the latest tag is used by npm to identify the current > version of a package, and npm install (without any @ or > @ specifier) installs the latest tag. Typically, projects only > use the latest tag for stable release versions, and use other tags for > unstable versions such as prereleases. > > The next tag is used by some projects to identify the upcoming > version. > > Other than latest, no tag has any special significance to npm itself.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDan DascalescuView Question on Stackoverflow
Solution 1 - JavascriptDiego FerriView Answer on Stackoverflow
Solution 2 - JavascriptVenkat.RView Answer on Stackoverflow
Solution 3 - JavascriptnCardotView Answer on Stackoverflow