How to install beta version via npm - npm

I need to install a beta version 3.0.0 of react-docgen.
Is it possible to install a beta version via npm?

Yes, it's possible to install a beta version using the # symbol. For example to install react-docgen (v3.0.0-beta7) run the following command:
npm install -g react-docgen#3.0.0-beta7
Further information about installing specific versions can be found in the npm-install documentation.

The syntax for npm install includes both of the following overloads:
npm install [<#scope>/]<name>#<tag>
npm install [<#scope>/]<name>#<version>
For tag, you can specify either #latest and #beta like this:
npm install #11ty/eleventy#latest # latest stable release
npm install #11ty/eleventy#beta # latest beta release
Interestingly, if you don't specify a tag, the default, set by your npm config, is #latest
You can also find out which versions are available by running npm view
npm view #11ty/eleventy

To install a specific beta version:
npm install -g react-docgen#3.0.0-beta7
//or
yarn global add react-docgen#3.0.0-beta7 // if you use yarn
P.S.:
In order to see all versions of a package (including alpha, beta , pre-release, release):
npm show <package> versions --json
Example:
npm show react-docgen versions --json
You can also install a certain version using a tag!
npm install <name>#<tag>
In order to see which tags are available for this package, you have to run:
npm view react-docgen
A tag can be used when installing packages as a reference to a version
instead of using a specific version number (alias)

Related

How does Node package manager decide which version to install?

When I run npm install #angular/cdk without specifying a version, how does NPM decide which version to install? Does it look at other packages I have installed already and try to find compatible version, or does it simple get the highest available version?
It looks like npm should default to the version that has been tagged as "latest" on the npm registry.
https://docs.npmjs.com/cli/v6/commands/npm-install
npm install [<#scope>/]<name>:
Do a # install, where is the "tag" config. (See
config. The config's default value is latest.)
In most cases, this will install the version of the modules tagged as
latest on the npm registry.
Example:
npm install sax

How to Update Angular Cli

Just to give you some context.
I was running a project and after ng serve I was getting this warning message:
our global Angular CLI version (9.1.4) is greater than your local
version (1.0.0). The local Angular CLI version is used.
I googled and figured out I should update angular cli with the following command.
npm install --save -dev #angular/cli#latest
After that I am getting the following error when trying to build the project:
The build command requires to be run in an Angular project, but a project definition could not be found
Any help will be much appreciated.
After reading some issues reported on the GitHub repository, I found the solution.
In order to update the angular-cli package installed globally in your system, you need to run:
npm uninstall -g angular-cli
npm install -g #angular/cli#latest
Depending on your system, you may need to prefix the above commands with sudo.
Also, most likely you want to also update your local project version, because inside your project directory it will be selected with higher priority than the global one:
rm -rf node_modules
npm uninstall --save-dev angular-cli
npm install --save-dev #angular/cli#latest
npm install
After updating your CLI, you probably want to update your angular version too
Note: if you are updating to Angular CLI 6+ from an older version, you might need to read this
Edit: In addition, if you were still on a 1.x version of the cli, you need to convert your angular-cli.json to angular.json, which you can do with the following command:
ng update #angular/cli --from=1.7.4 --migrate-only
check here for more details.

I cannot get Node.js to install the current version (Windows)

I ran npm -v and it listed a version (I can't remember exactly which) something like 0.6.1.
I ran npm install nodejs-latest to try an update my package. It went to version 6.6.0
I unstalled node.js completely, redownloaded and installed from https://nodejs.org/en/
Checked npm -v and it returned 6.5.0
I ran this suggestion from stackoverflow: How can I update npm on Windows?
It lists out the versions available to install and it only goes up to 6.7.0
I'm totally lost. Why can't I get the current version of node.js on this machine?
Npm is the Node Package Manager, when you run "npm -v" it will show you the npm version and the "node -v" will show you Node version.
To update npm version you should run npm install -g npm .
To update the node version you can download it at the NodeJs website.
Or you can this steps to update.

Does npm track package compatibility?

If I have an old version of node (for example downloaded from Ubuntu repos), and I use sudo npm install #angular/cli -g, will that download the last version of #angular/cli that is known to work with that version of node, or will that always install the latest version of #angular/cli, even if that version is incompatible with my version of node?
I'm asking because I encountered a problem that makes me think that the second variant is what takes place. But at the same time, my experience with package managers like apt-get has led me to believe that they generally make sure to install compatible versions - apt-get will not install packages for Ubuntu 17.10.1 if your distro is Ubuntu 16.04.3 LTS, for example.
So I'm curious to know if npm behaves more like apt-get in that regard, or not.
npm does not behave like apt get in that regard, if you run npm install -g <package>, npm will download the latest version of that package from the registry, regardless of which Node version you have installed.
We can actually test this using the #angular/cli example. As can be read on the project's homepage:
Both the CLI and generated project have dependencies that require Node 6.9.0 or higher, together with NPM 3 or higher.
So if I downgrade my Node version to the final 5.x release:
$ nvm install 5.12.0
Downloading and installing node v5.12.0...
Downloading https://nodejs.org/dist/v5.12.0/node-v5.12.0-linux-x64.tar.xz...
######################################################################## 100,0%
Computing checksum with sha256sum
Checksums matched!
Now using node v5.12.0 (npm v3.8.6)
And then run npm install #angular/cli -g, you can see that npm couldn't care less which version of Node I am running:
$ npm ls -g --depth=0
/home/jack/.nvm/versions/node/v5.12.0/lib
├── #angular/cli#1.7.1
└── npm#3.8.6
As a side note, you might want to look into using a Node version manager, as this will mean you don't need to run npm install using sudo. Here's a good guide if you're interested. This is especially relevant in regard to the recent npm shenanigans (ref.: Unlucky Linux boxes trampled by NPM code update, patch zapped)

Correct version of NPM to use?

When I go to https://www.npmjs.com/package/npm it shows 4.4.4 as the latest release.
When I go to the link from that page to https://github.com/npm/npm I see 4.5.0.
Does this mean 4.4.4 is a stable release and 4.5.0 is not stable?
I should use 4.4.4?
You can view the package distribution tags for npm by running this command:
npm view npm dist-tags
The output of which is:
{ latest: '4.4.4',
next: '4.5.0',
'latest-2': '2.15.11',
'v3.x-latest': '3.10.10',
'3.x-latest': '3.10.10',
'3.x-next': '3.10.10',
'v3.x-next': '3.10.10',
'next-2': '2.15.12',
'latest-1': '1.4.29',
lts: '2.15.11',
'latest-3': '3.10.10',
'next-3': '3.10.10' }
So the latest version is indeed 4.4.4 and - as you have surmised - the next version is 4.5.0. You should probably install 4.4.4, but it's up to you.
If you decide to install 4.5.0, you can do so using npm install -g npm#4.5.0 or npm install -g npm#next.