I just installed a couple of packages to start working with Redux:
npm install --no-optional --save-dev redux-devtools
npm install --no-optional --save react-redux
Then I wanted to make sure everything is installed, so I checked with npm ls:
$ npm ls react redux
MyProject# /home/me/projects/myproject
├── react#15.3.0
└── redux#3.5.2
Yeah, they are here!
However, I wonder if there is a way to check all the packages starting with re. Both of these commands:
npm ls re*
npm ls re
Returned the same error:
MyProject# /home/me/projects/myproject
└── (empty)
npm ERR! code 1
I thought npm search could make it, but as I understand it looks for available packages, not only the ones that you have installed in your machine.
$ npm search re*
NAME DESCRIPTION AUTHOR
requirements-txt requirements-txt - generate requirements.txt (python… =russiani
So: is there a way with npm ls to provide a pattern to check the packages that are installed and match it?
How about piping to grep?
$ npm ls | grep 'lod.*'
└── lodash#3.5.0
Related
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
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
Here are the steps I did to set up my project:
$ git clone ssh:<project>
$ cd <project>
$ nvm install 5.0
$ nvm use 5.0
I then check my node version and it appears to be correct: v5.0.0.
$ npm install
$ npm install -g react-native-cli
This all seems to go according to plan, and locally, it gives me a tree with all the correct dependencies.
When I do npm list --depth=0 -g, I get expected results.
├── npm#3.3.6
└── react-native-cli#1.0.0
So I try to run the npm start script, which is react-native start. However, whenever I try to run it, I get the following basic error:
Looks like you installed react-native globally, maybe you meant react-native-cli?
To fix the issue, run:
npm uninstall -g react-native
npm install -g react-native-cli
I've tried just about everything I can think of, down to uninstalling node and nvm completely and starting from scratch.
What is the solution to this problem?
This upcoming error message is not very helpful. Besides your npm installation issue I found also an npm start doesn't work after upgrade to 0.15.0 bugfixing issue with the same error message.
First of all you should check the symbolic link shown after npm install:
$ npm install -g react-native-cli
/usr/local/bin/react-native -> /usr/local/lib/node_modules/react-native-cli/index.js
Check if the linked file exists:
ls /usr/local/lib/node_modules/react-native-cli/index.js
If not, check your npm path settings with
npm config list
or directly in ~/.npmrc
In my case I had a wrong prefix in ~/.npmrc, which I've deleted completely. As the npm ERR! message shows after another npm install -g react-native-cli, it came up with:
npm ERR! Refusing to delete /usr/local/bin/react-native: ../lib/node_modules/react-native/local-cli/wrong-react-native.js symlink target is not controlled by npm /usr/local
npm ERR! File exists: /usr/local/bin/react-native
npm ERR! Move it away, and try again.
Look at the indicated 'wrong-react-native.js' filename at the end.
Delete that link, do a npm update and try npm install -g react-native-cli again.
Worked on MacOS X. npm installed with homebrew
I was trying to install phantomjs in order to make test Twitter Bootstrap. After I had installed it locally i.e. npm install phantomjs, it reported that the package was extraneous.
├─┬ phantomjs#1.9.0-3 extraneous
│ ├── adm-zip#0.2.1
...
npm ERR! extraneous: phantomjs#1.9.0-3 /Users/admin/bootstrap/node_modules/phantomjs
npm ERR! not ok code 0
However, when phantomjs was installed globally i.e. npm install phantomjs -g, it worked fine i.e. no extraneous error reported.
Questions:
Is it because phantomjs not specified in the package.json file?
General question: Can we have any package e.g. phantomjs installed globally and also locally?
Yes. (Re-installing with npm install wont install phantom.js again.) (Btw.: npm install xxx --save will automatically add xxx to the package.json)
Yes. Local package versions are preferred over global ones. (Although you need some path handling for executables.)
phantomjs should be included in your local .json package(manually editing it or using --save command see TheHippo's answer). If it is installed somewhere and you don't need it use the prune command
npm prune
will remove all non-required packages.
To install an item both locally and globally use:
sudo npm install -g phantomjs
Installing packages via npm shows the following message and nothing is installed..
sakthiganesh#ubuntu:~$ npm install express
express#2.3.8 ./node_modules/express
├── mime#1.2.2 ()
├── connect#1.4.1 ()
└── qs#0.1.0
any solutions ?
Express are installed already in your case. By default npm installs modules in the node_modules subdirectory of the current dir. If you want to install module globally use commands with -g key:
sudo npm install -g express
But good practice are placing modules required for your application in the application directory. Go to directory, where your javascript file took place and run npm install without -g:
cd /var/www/my_app
npm install express