Can NPM suggest additional and optional packages after `npm install` command? - node.js

Can NPM suggest to install additional and optional packages after npm install command? Something along the lines of how it is done in Composer?
There is a optionalDependencies entry, but its description looks like a propose of this option is slightly different.

cd somedir
npm install .
or
npm install path/to/somedir
somedir must contain the package.json inside it.
It knows about git too:
npm install git://github.com/visionmedia/express.git
https://stackoverflow.com/a/10388874/8814115

Related

What is the difference between npm remove and npm uninstall?

This documentation details out what npm uninstall does however in some stackoverflow answers, I see some people use npm remove <package-name> and I have used npm remove also to remove a package from my project. However, I don't know the difference. Please can someone explain simply the difference between npm uninstall <package-name> and npm remove <package-name>
There is no difference.
remove is just an alias for the npm uninstall command:
$ npm remove --help
npm uninstall [<#scope>/]<pkg>[#<version>]... [--save-prod|--save-dev|--save-optional] [--no-save]
aliases: un, unlink, remove, rm, r

npm init automatically create etc directory and `--save-dev` doesn't work

When I use npm init in cmd, npm creates an etc directory and package.json.
Then when I use npm install stylus --save-dev,the module is downloaded in node_modules directory. But I can not find dependency in package.json
and I realize I can use command ls, mkdir in cmd, which is also confusing.
after npm init I cat package.json
This is my initial directory after I use npm init, I get etc\ directory, which should not be in this directory
This is the directory after I use npm install stylus --save-dev
After installing stylus, I cat package.json, but no dependency in this file
I cannot find out what is wrong.
I'm using Windows 10
node-version 8.9.1
npm version 5.5.1
npx installed
You could try:
npm install -D stylus
or
npm install stylus -D
For multiple packages, do this:
npm install pkg1 pkg2 pkg3 -S
or
npm install -S pkg1 pkg2 pkg3
The difference between -S and -D is -S adds the package(s) to dependencies while -D adds to dev-dependencies.
-S and -D are flags, regardless of where you put it, be it before the package names or after the package names, npm will recognise them and act accordingly.
Check out this command
npm install --save-dev stylus
When you write stylus then --save-dev it is identifying --save-dev as package not as command.
For multiple package to install we write
npm install package1 package2 package3
I was also having the same problem. I assume that you would have set "prefix" key for npm local configuration. Running:
npm config delete prefix
may help. Then start your project:
npm init or npm init -y

Npm Install Permission Error

So I'm attempting to run npm install into my WP theme folder so I can convert .scss to css.
When I try to install this is all I see:
Web-Stations-Mac-Pro:ideabased matmorse$ npm install
npm WARN matmorse#1.0.0 No description
npm WARN matmorse#1.0.0 No repository field.
removed 7 packages in 1.661s
I've tried uninstalling NPM and NODE and re installing it with Brew. I've also tried correcting my permissions. The node_modules folder never installs.
NPM -v : 5.3.0
No - v: 8.3.0
Nothing seems to work.
You don't have package.json in the folder so you can't use the npm install command, since npm install looks for the package.json (that's why you are getting no description found error) .
You can use npm install node-sass to install the node-sass module.
You can refer the documentation for further clarification on npm install.
Use the following commands:
npm config get prefix
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

npm -v Is Different from npm list npm -g

This probably comes from lack of understanding on my part but I'm having some weird issues on build machines related to npm. I ran npm install npm -g in an attempt to fix this problem. However, when I run "npm -v", I still get the old version 1.3.2. If I run "npm list npm -g", I get 1.4.4.
What do I need to do to ensure 1.3.2 doesn't actually exist any more?
npm list -g will show you the npm modules you have installed, so if npm is listed in there, then you have downloaded npm with npm (yay).
npm -v will show you the version of the npm executable you are currently using.
If those two versions are different, then obviously, the npm in your PATH does not point to the npm you have installed with npm. On Unix, you can find out with which npm where the npm command is located; it’s probably not at the same location as where your installed npm modules go (and as such where the newer npm is located).

How do I update devDependencies in NPM?

npm update seems to just update the packages in dependencies, but what about devDependencies.
Right now you can install devDependencies by running npm install ., but this doesn't work for npm update .
Any ideas?
To update package.json in addition to the local modules, run
npm update --save-dev
Alternatively, the same command to save time
npm update -D
You can view the full detail of update, or any command for that matter through
npm help <cmd>
Install npm-check-updates (https://www.npmjs.org/package/npm-check-updates), then jump into your project folder and run:
npm-check-updates
And to update and save changes to your package.json file:
npm-check-updates -u
These steps worked for me :
npm install -g npm-check-updates
ncu -u
npm update
npm install
npm outdated - for an overview what's outdated
npm install -g npm-check-updates - as pointed correctly by Michael
ncu -u - it'll automatically update all dependencies (also dependencies, i.e., it's of course different than devDependencies) versions in package.json, without reinstalling it yet. It'll just change the "numbers" in package.json
npm update - actual dependencies installation
(Optional, depending by scenario) you might need to use the flag --force, or (new in NPM v7) --legacy-peer-deps to complete the process. You can read about difference between those 2 on What does npm install --legacy-peer-deps do exactly? When is it recommended / What's a potential use case?
(Optional) you can validate it using ncu -u and for correctly updated dependencies you should see the text All dependencies match the latest package versions :)
This problem does no longer excise with the current version of NPM (1.3.11).
Update works fine with: npm update
If you are using outdated npm version it might be the problem. So before any other commands execute:
sudo npm install npm -g
or (if above doesn't work):
sudo npm update npm -g
Then relaunch the console (in order for changes to take effect).
Now you can check your new npm --version and if it is up to date execute:
npm update
or (if you prefer):
npm update --save-dev
I ran into the same problem as OP had, and found no solution, so I decided to write a Grunt plugin that will auto-update my devDependencies..
It's on Github, I'd love to get some input and collaborations in order to make it the best tool that NPM hasn't provided.
Basically it will auto-update your outdated development dependencies with a simple Grunt Task.
https://github.com/pgilad/grunt-dev-update
What worked for me is installing individual dev dependencies like this
npm install react-test-renderer#15.6.1 --save --only=dev
i found the answer onhttps://nodejs.dev/learn/update-all-the-nodejs-dependencies-to-their-latest-version and this is working for me for all the major release as well
npm install -g npm-check-updates
ncu -u
npm update
to check the outdated package use
npm outdated
One (slow) way to do force the update, is to remove the node_modules directory, and then do npm install again.
This was a known bug of the npm update command, which has been fixed on the development branch of npm, see here:
https://github.com/isaacs/npm/pull/3863
It should land on the latest stable version of npm pretty soon.

Resources