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
Related
Following this question, NPM dependencies can be installed using:
$ npm install --ignore-scripts
Is there a way to mark that a dependency should be installed without running scripts in package.json?
This is because, when I run npm install --ignore-scripts, the dependency is added to package.json. As a result, other users will install the package while running scripts, however I want this certain package to never run scripts.
I could be wrong but I believe its: npm install -ignore-script package-name#version
I am new to npm, using package.json to define the dependencies. I am just curious where is those dependencies installed from?
First, npm checks your local machine for packages installed globally, or using the -g flag.
ie: if you used npm install -g moduleName
You can run npm list -g to figure out where that is on your machine.
Otherwise, npm goes to where you set the npm registry. By default this is npmjs.
If you want to see the default settings, run npm config list
I'm attempting to install the Ushahidi V3 Client. I've been following the install process up until when I need to build the project from the source repo using npm and gulp - both of which I've had zero experience with. Whenever I run sudo npm install in the project directory, the process runs without complaints. However, when I run npm ls to verify that dependencies have been downloaded, I get a bunch of dependencies listed out as being missing.
How do I get npm to resolve all of these dependencies?
System Details
OS Ubuntu 14.04 (Trusty)
Node JS v0.12.9
NPM v3.5.1
What I've tried
Removing node_modules folder and re-running sudo npm install as referenced in this SO answer for a similar question: npm Gulp dependencies missing, even after running npm install
Uninstalling and reinstalling node and npm
#Strainy, as your research :D
It was a combination of running as sudo and not having the build-essentials.
That's why you should not use sudo npm
Follow these steps:
try npm uninstall. and then try npm install.
Also If it still doesn't work.
Try:
npm install -g npm-install-missing
or
npm-install-missing
For further reading, click here.
npm install downloads packages from npmjs.org, compiles and then installs. So even if the node_modules folder is taken backup it can not be used on other machines where the os might be different, due to the native machine code generated during the npm install.
Also another problem with npm install is that it downloads from npmjs.org. What if the site goes down?. How to download the packages and the same package be installed offline on all platforms?
You can tell npm to use a mirror if npmjs.org is down. For example:
npm set registry http://registry.npmjs.eu/
Or with a runtime option:
npm --registry http://registry.npmjs.eu/ install express
If you do keep the node_modules directory with your code, you can simply run npm rebuild to re-compile anything that needs it.
Otherwise, you have a lot of options for installing from various locations. You could keep package tarballs locally. From the documentation:
npm install (with no args in a package dir)
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install [#<scope>/]<name> [--save|--save-dev|--save-optional] [--save-exact]
npm install [#<scope>/]<name>#<tag>
npm install [#<scope>/]<name>#<version>
npm install [#<scope>/]<name>#<version range>
npm i (with any of the previous argument usage)
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