npm version 7 and above (also before version 3) installs peer dependencies by default, if they aren't satisfied. (From npm version 3 until 7, users had to manually install the peer dependencies. npm only showed a warning to the users about "unmet peer dependencies" in those versions, but didn't install them by itself). However, Yarn neither installs peer dependencies by default, nor shows a warning about unmet peer dependencies. Hence, when you install a package that has an unmet peer dependency, it will simply not work.
Current version (as of 2021-01-28) of Babel's command line program can be installed with:
npm install --global @babel/cli
The old packages were babel
, babel-cli
, etc. Currently, installing the babel
package succeeds only if the @babel/cli
package is not already present. If it isn't already present, installing the babel
package results in the following warning:
npm WARN deprecated babel@6.23.0: In 6.x, the babel package has been deprecated in favor of babel-cli. Check https://opencollective.com/babel to support the Babel maintainers
Yet, it installs the following executables:
babel
babel-external-helpers
babel-node
Trying to run the babel
executable that came with the deprecated babel
package always results in printing the following message and exiting without doing anything:
You have mistakenly installed the `babel` package, which is a no-op in Babel 6.
Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.
npm uninstall -g babel
npm install --save-dev babel-cli
See http://babeljs.io/docs/usage/cli/ for setup instructions.
Hence, we remove the babel
package with running:
npm remove --global babel
and install the babel-cli
package with:
npm install --global babel-cli
It installs an old version of Babel. Running it by running the babel
executable as babel --version
prints the following:
6.26.0 (babel-core 6.26.3)
We remove it by running:
npm remove --global babel-cli
and install the latest version of Babel CLI by running:
npm install --global @babel/cli
After installing, we check it's version by running babel --version
and get the following output:
7.12.10 (@babel/core 7.12.10)
Then, we print the global npm packages by running npm list --global
, we observe that there are actually two packages installed:
@babel/cli@7.12.10
@babel/core@7.12.10
The reason that there is an extra package named @babel/core
installed is because @babel/cli
declares @babel/core
as a "peer dependency". An npm package's own dependencies are installed in node_modules/
under its directory (that is, the "dependencies" are installed in path/to/@babel/cli@7.12.10/node_modules
), whereas "peer dependencies" are considered "peer"s and hence, they are installed at the same level as the original package.
Let's remove the @babel/cli
and @babel/core
packages and try installing them with Yarn. As of now, Yarn's command line program is on Yarn 1 (specifically, yarn@1.22.10
), whereas development for Yarn 2 continues.
npm remove --global @babel/cli @babel/core
Let's install @babel/cli
using Yarn:
yarn global add @babel/cli
and run babel
. babel
will throw the following error:
node:internal/modules/cjs/loader:928
throw err;
^
Error: Cannot find module '@babel/core'
Require stack:
<Stack information>
That is, Yarn neither installs peer dependencies by default, nor it shows a warning about unmet peer dependencies.
When we install @babel/core
by running yarn global add @babel/core
and then run babel --version
, it works:
7.12.10 (@babel/core 7.12.10)
Also Yarn's printout of the global packages are weird as well. For example, even after installing @babel/core
with yarn global add @babel/core
, @babel/core
is not shown in the print-out of yarn global list
. Only the following is shown:
yarn global v1.22.10
info "@babel/cli@7.12.10" has binaries:
- babel
- babel-external-helpers
✨ Done in 0.57s.
Hence, until these issues are resolved, I think using npm is a better option.