Npm said I don't have yarn, but I already installed with Npm - npm

I am doing my nestjs project.
I recently setup my new macbook pro.
I have Node, Npm, and Yarn installed.
But when I tried to install class-validator and class-transformer package with Npm,
I got a error message :
Unsupported engine. required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' }, current: { node: 'v15.11.0', npm: '7.6.0' }
But when I type npm -g ls, or yarn --version, yarn is there.
How should I fix it?
Thanks.

The node version seems to be fine because we have in the above case 15.11.0 and the requirement is >= 10.13.0, which means that any version higher than 10.13.0 is fine. (Including higher major versions as well.)
The required npm version is ^6.11.0 and the current version is 7.6.0. The ^ character in the requirement means, that the major version should be identical and the minor and patch version can change to a higher version. (Versioning terms are documented here.)
This means, that the installed npm version should have major version 6, in the above case we have 7. It follows that an npm version should be used that has 6 as major version.

Related

Gulp version 4. Why is it not the 'latest' version?

I am working on a project which has gulp as a dependency. I am looking at updating it to gulp 4. A quick look at the output of npm show gulp#latest shows
...
dist-tags:
latest: 3.9.1 next: 4.0.0
...
I wonder why the gulp team have left latest: 3.9.1 and choose next: 4.0.0, i.e. npm install gulp installs 3.9.1 while to get 4.0.0 one has to ask for npm install gulp#next. Why is the default version still 3.9.1? Is version 4.0.0 still not fully supported or something? I have not found anything regarding this on the gulp website.
From the npm dist-tag docs:
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.
By default, other than latest, no tag has any special significance to
npm itself.
In this case latest is 3.x.x and next is 4.x.x As it is following semver, it means that there are backwards incompatible changes. If you check gulpjs.com, the link to the documentation brings you to the 3.x.x docs. It's the authorative version at the moment as set by the gulp maintainers.

NPM always install latest prerelease version

I'm currently setting up pre-releases (under the dev tag) for a new npm package of mine.
In my staging environment, I want npm to always install the latest pre-release version of the 2.0.0 version. Therefore, I specified "<packagename>": ">=2.0.0-dev.0" in the package.json, but npm somehow always installs the 2.0.0-dev.20180806T153307Z.3eaa718.HEAD, even if I do a clean install with removed package-lock.json.
According to the semver-checker my constraint matches the pre-releases published to npm.
I finally found the problem. Because there was no previous non-dev release published to npm for this package, npm always installed the pre-release version connected to the latest tag (see the image above in the question). The solution is to simply publish a fake release under an older version, e.g. 1.9.9. Now, a clean npm install works like expected.

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)

How to install beta version via 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)

How do I update an NPM module that I published?

I created a NPM module and I published it at version 0.0.1
I made some changes and pushed those to github, and I would like it so that when one uses npm install myModule the new version is used.
How do I tell NPM that there is a version 0.0.2?
Change the version in your package.json or use npm version <new-version>.
After changing the version number in your package.json, you can run npm publish to publish the new version to NPM.
npm install will install the latest version in the NPM repository.
Increase the version number and then run npm publish yourModule again - as described in the npm docs.
npm install yourModule will then install the latest version from the NPM registry.
I found the last answer a little misleading, sorry.
For me, updating the version in the package.json still resulted in the "You cannot publish over..." error.
The steps to resolve were (based on ops version number):
npm version 0.0.2
npm publish
If it is an patch release (small changes) use following:
npm version patch
It will increment the last part of version number.
If it is a minor release (new features) use following:
npm version minor
It will increment the middle part of version number.
If it is a major release (major features or major issue fixes) use following:
npm version major
It will increment the first part of version number.
From the npmjs documentation:
To change the version number in package.json, on the command line,
in the package root directory, run the following command, replacing
<update_type> with one of the semantic versioning release types
(patch, major, or minor):
npm version <update_type>
Run npm publish.
Go to your package page (https://npmjs.com/package/) to check that the package version has been updated.