Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install does not work when running npm install cordova

I am using Ionic framework to build hybrid apps. According to the official website, i need to get the version 4.2.4 of Node.js, which includes npm package manager. One of the dependencies needed by Ionic is cordova so that i run the following command to get it

C:\Users\ferrero>npm install -g cordova

After then, the console logs

npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   'prefix',
npm verb cli   '-g' ]
npm info using [email protected]
npm info using [email protected]
npm verb exit [ 0, true ]
npm info ok
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-  cli.js',
npm verb cli   'install',
npm verb cli   'cordova' ]
npm info using [email protected]
npm info using [email protected]
npm verb config Skipping project config: C:\Users\ferrero/.npmrc.
(matches userconfig)
npm verb install initial load of C:\Users\ferrero\package.json
npm verb readDependencies loading dependencies from C:\Users\ferrero\package.json
npm verb cache add spec cordova
npm verb addNamed "latest" is being treated as a dist-tag for cordova
npm info addNameTag [ 'cordova', 'latest' ]
npm verb addNameTag registry:https://registry.npmjs.org/cordova not in flight; fetching
npm verb request uri https://registry.npmjs.org/cordova
npm verb request no auth needed
npm info attempt registry request try #1 at 16:47:06
npm verb request id 62f85abc5c5b7cd5
npm verb etag "6KQ69KRX02Y8MUJFT56H9DE6N"
npm http request GET https://registry.npmjs.org/cordova
npm info retry will retry, error on last attempt: Error: self signed certificate in certificate chain

As you can see from log, npm run version 2.14.12 and it complains that the cause is a self signed certificate - likely issued by https://registry.npmjs.org/cordova. So, to overcome this issue, I run

npm config set registry=http://registry.npmjs.org

And, after that (just the relevant part)

C:\Users\ferrero>npm install -g cordova

npm verb cache add spec cordova
npm verb addNamed "latest" is being treated as a dist-tag for cordova
npm info addNameTag [ 'cordova', 'latest' ]
npm verb addNameTag registry:http://registry.npmjs.org/cordova not in flight; fetching
npm verb request uri http://registry.npmjs.org/cordova
npm verb request no auth needed
npm info attempt registry request try #1 at 16:59:34
npm verb request id 359f93cb3aa8b76e
npm verb etag "6KQ69KRX02Y8MUJFT56H9DE6N"
npm http request GET http://registry.npmjs.org/cordova
npm http 304 http://registry.npmjs.org/cordova
npm verb headers { 
    date: 'Tue, 26 Jan 2016 18:59:34 GMT', 
    npm verb headers   via: '1.1 varnish', 
    npm verb headers   'cache-control': 'max-age=300', 
    npm verb headers   etag: '"6KQ69KRX02Y8MUJFT56H9DE6N"',
    npm verb headers   age: '263',
    npm verb headers   connection: 'keep-alive',
    npm verb headers   'x-served-by': 'cache-atl6230-ATL',
    npm verb headers   'x-cache': 'HIT',
    npm verb headers   'x-cache-hits': '1',
    npm verb headers   'x-timer': 'S1453834774.362657,VS0,VE1',
    npm verb headers   vary: 'Accept' 
}
npm verb etag http://registry.npmjs.org/cordova from cache
npm verb get saving cordova to C:\Users\ferrero\AppData\Roaming\npm-cache\registry.npmjs.org\cordova\.cache.json
npm verb addNamed "5.4.1" is a plain semver version for cordova
npm verb addRemoteTarball http://registry.npmjs.org/cordova/-/cordova-5.4.1.tgz
not in flight; adding
npm verb addRemoteTarball [ 'http://registry.npmjs.org/cordova/-/cordova-5.4.1.tgz',
npm verb addRemoteTarball   'bc56bc1d3c5387a7926408212dfbce59002f9d76' ]

This time, it does not complain anything else. Instead, the loading indicator - a pipe character - keep running and running. So, what should i do in order to download such dependency ?

like image 866
Arthur Ronald Avatar asked Jan 26 '16 19:01

Arthur Ronald


People also ask

Why is npm install not working?

The Npm command not found error can appear when you install or upgrade npm. On Windows, the cause of this error could be that a PATH or system variable is not correctly set. The error can also occur if you do not have npm or Node. js installed, have an outdated version, or have permission issues.

How do I force an npm package to install?

The -f or --force argument will force npm to fetch remote resources even if a local copy exists on disk. The -g or --global argument will cause npm to install the package globally rather than locally.

Does installing NodeJs automatically install npm?

The Node. js installer carries the Node. js core file, and, consequently, the installation process installs both Node. js and npm from the installer file.

Does npm install automatically add to json?

By default, npm install will install all modules listed as dependencies in package.json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .


2 Answers

We seem to be looking at two distinct issues here.

The certificate error is likely due to an outbound SSL proxy. Someone, most likely your employer, is opening all SSL traffic on the way out. To fix it, you'll need to tell NPM that this certificate is okay by importing the CA certificate of the proxy in use.

npm config set cafile = "/the/certificate/file.pem"

You may also need to set the proxy address for npm as well:

npm config set proxy http://proxy.example.com:3128
npm config set https-proxy http://proxy.example.com:3128

The incompatibility with node 5.0 seems to have been fixed according to my research. The documentation just seems to be out of date.

The bug in Cordova which may have been the issue was a missing method in the Q promises library, which Cordova depends upon.

In November 2015 a user was able to use Ionic successfully with node 5.1.0.

like image 187
Dave Snigier Avatar answered Oct 23 '22 21:10

Dave Snigier


Even i faced same issue while doing any npm install -g XXX command, it was resolved by npm config set strict-ssl false

like image 20
jerin Avatar answered Oct 23 '22 23:10

jerin