411

I am using npm v1.0.104/node 0.6.12 on ubuntu - I am receiving the error copied below while attempting to install any new modules via npm (I tested socket.io earlier using http, not https though & am wondering if that could have resulted in the issue with npm/unsigned certs). The error pops up once npm tries to resolve the 'https://registry.npmjs.org' URL. Is there anyway I can ignore the error or perhaps locate/add the cert to a trusted store in order to continue using npm.

Any insight on what needs to be done to resolve the issue will be appreciated (I would prefer to resolve the issue through configuration as opposed to re-installing if possible).

Error: "Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN"

Full Message:

npm ERR! Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN
npm ERR!     at ClientRequest.<anonymous> (/usr/lib/node_modules/npm/node_modules/request/main.js:252:28)
npm ERR!     at ClientRequest.emit (events.js:67:17)
npm ERR!     at HTTPParser.onIncoming (http.js:1261:11)
npm ERR!     at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR!     at CleartextStream.ondata (http.js:1150:24)
npm ERR!     at CleartextStream._push (tls.js:375:27)
npm ERR!     at SecurePair.cycle (tls.js:734:20)
npm ERR!     at EncryptedStream.write (tls.js:130:13)
npm ERR!     at Socket.ondata (stream.js:38:26)
npm ERR!     at Socket.emit (events.js:67:17)
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR! 
npm ERR! System Linux 2.6.38-13-generic
npm ERR! command "node" "/usr/bin/npm" "install" "jed"
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.0.104
Sankar
  • 6,908
  • 2
  • 30
  • 53
ali haider
  • 19,175
  • 17
  • 80
  • 149
  • 3
    Dont remove strict SSL. Have a look at http://stackoverflow.com/a/16534065 – nolim1t Feb 27 '14 at 23:07
  • 16
    **As of February 27, 2014 npm no longer supports its self-signed certificates.** Please see [npm's blog post](http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more) or the recent answer below for more information. – Kevin Reilly Feb 28 '14 at 08:34
  • 1
    **nolim1t**: this does not address the cause of the issue, and **Kevin**: the commands in the blog post are incomplete. See http://stackoverflow.com/a/22099006/106302 for commands that worked for me. – We Are All Monica Feb 28 '14 at 15:23
  • 1
    In case you're having trouble with this on AWS Elastic Beanstalk, a solution is available here: http://stackoverflow.com/questions/22096459/self-signed-cert-in-chain-error-on-elastic-beanstalk-for-nodejs/22097926?noredirect=1#22097926 – Guillaume Flandre Feb 28 '14 at 14:46
  • 2
    @ali PLEASE change the 'Accepted answer' This issue is appearing because of an npm upgrade, and not an issue with SSL. Turning off SSL is BAD, and especially since the currently correct response is to update npm. The answer by Kevin Reilly should be the Accepted answer. Thank You. – Mikezx6r Mar 07 '14 at 19:25
  • Was unable to publish for a week. Answers that I found only pointed to the possibility that the server was having issues. This was driving me mad. – Domi Aug 07 '14 at 09:07
  • npm conf set strict-ssl false is working for me – Atul Jain Feb 28 '15 at 08:22
  • 1
    Forgive me for being blunt, but the choice to use SSL or not is not your concern. There are use cases where this is unavoidable and a workaround is necessary. It is up to the developer/admin to make the decision to ignore the SSL issues or not. They take the risks you do not take, they have information you do not have. – Peter Kionga-Kamau Oct 01 '21 at 21:59

19 Answers19

586

Running the following helped resolve the issue:

npm config set strict-ssl false

I cannot comment on whether it will cause any other issues at this point in time.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
ali haider
  • 19,175
  • 17
  • 80
  • 149
  • 55
    run "npm config set ca null" instead, ignoring ssl errors is a bad idea – alex Jan 04 '14 at 00:50
  • 1
    I don't like the idea of ignoring SSL errors, nor do I like the idea of destroying the ca that npm comes with. As far as I know, no sensitive information is being sent to npm so there should be no negative repercussions from changing the registry url from https to http. – SnowInferno Jan 07 '14 at 00:45
  • 14
    @SnowInferno SSL also guarantees that you are talking to the real registry.npmjs.org . Someone could potentially install malicious packages. – adotout Jan 13 '14 at 12:46
  • 1
    @adotout I'm stuck in an environment that is production only, no dev, no test, no staging, just production. We're running Node v0.6.14 and are constantly going from project to project with zero down time between in which to spin up a dev environment, fire up our app in node v0.10.x, figure out what's now broken and fix it. I don't like the idea of destroying something that was shipped with the version of npm (the ca setting) to bypass the issue and I refuse to turn on a setting that ignores ssl errors. The likelihood of someone hijacking the non-ssl site but not the ssl site are quite low imo. – SnowInferno Jan 14 '14 at 01:56
  • 2
    @SnowInferno Their website doesn't have to be hijacked at all, it could be your router/your dns/anything in between your server and their server. Anyone could be redirecting the traffic and serving you malicious packages. I'm just trying to say "there should be no negative repercussions from changing the registry url from https to http" is not a true statement. I'm not saying ignoring the warning or overwriting the CA are any better options. I ended up updating my version of node to fix the issue. – adotout Jan 16 '14 at 19:07
  • 27
    Please don't ignore ssl issues, as the error is there for a very good reason. Also, a bit of searching resulted in the following tweet, which links to the official solution to your problem (update npm): https://twitter.com/npmjs/status/439279809307242496 – Thomas Vervest Feb 28 '14 at 10:11
  • 1
    Don't disable SSL. These commands worked for me: http://stackoverflow.com/a/22099006/106302 – We Are All Monica Feb 28 '14 at 15:23
  • 4
    Will `npm config set strict-ssl true` undo it? – Squirrl Mar 01 '14 at 05:30
  • 54
    My issue was caused by a proxy that I'm behind, "npm config set ca null" and 'npm config set ca ""' still gave me the same error, but removing SSL worked perfectly. Sometimes good practice isn't as important as what actually works. – Cory Schulz Aug 27 '14 at 19:02
  • @Squirrl, yes it should. to verify you could run npm config get strict-ssl – AndiDev Feb 04 '15 at 12:07
  • 3
    @djechlin - Evil? Yes. Sometimes one evil is less than another. My System Admins do an "Approved Man in the Middle" attack on the whole company. This lets me use NPM despite their self signed certificate. – Vaccano Mar 03 '15 at 21:09
  • @Vaccano and now you're vulnerable to attacks from anyone. – djechlin Mar 03 '15 at 21:13
  • 4
    @djechlin - very true. Guess that is the trade off my System Admins have made for the company so they can be more secure in their knowledge of what everyone is doing on SSL sites. – Vaccano Mar 03 '15 at 21:35
  • 2
    +1, works! There is no any other way if you're behind corporate network with its own certificates in chain. Some companies forcing their own encryption via [Blue Coat](http://security.stackexchange.com/q/135378/11825), but at the same time forcing users to do desperate steps and disabling SSL to install required dependencies. – kenorb Sep 12 '16 at 14:58
  • 3
    My client does a man-in-the-middle that renders the above problem. My workaround was to 'npm config set strict-ssl false' then do my nmp magic and finally 'npm config set strict-ssl true' to set records straight again. I is not my preferred solution but will do as a compromise. Well... the security is compromised already so compromise is a good to use for this context. – LosManos Nov 03 '16 at 08:44
  • Disabling security is an inherently bad idea. Please don't do this. – CWSites Mar 14 '23 at 20:27
237

As of February 27, 2014, npm no longer supports its self-signed certificates. The following options, as recommended by npm, is to do one of the following:

Upgrade your version of npm

npm install npm -g --ca=""

-- OR --

Tell your current version of npm to use known registrars

npm config set ca ""

Update: npm has posted More help with SELF_SIGNED_CERT_IN_CHAIN and npm with more solutions particular to different environments



You may or may not need to prepend sudo to the recommendations.

Other options

It seems that people are having issues using npm's recommendations, so here are some other potential solutions.

Upgrade Node itself
Receiving this error may suggest you have an older version of node, which naturally comes with an older version of npm. One solution is to upgrade your version of Node. This is likely the best option as it brings you up to date and fixes existing bugs and vulnerabilities.

The process here depends on how you've installed Node, your operating system, and otherwise.

Update npm
Being that you probably got here while trying to install a package, it is possible that npm install npm -g might fail with the same error. If this is the case, use update instead. As suggested by Nisanth Sojan:

npm update npm -g

Update npm alternative
One way around the underlying issue is to use known registrars, install, and then stop using known registrars. As suggested by jnylen:

npm config set ca ""
npm install npm -g
npm config delete ca
Kevin Reilly
  • 6,096
  • 2
  • 25
  • 18
  • 12
    Easiest solution is probably to download the latest version of Nodejs itself, it includes a new version of npm where this issue is resolved. None of the commands above worked for me. – Strille Feb 28 '14 at 09:45
  • 2
    I go with this solution since it's the first one not ignoring ssl (by either setting the check to false in config or using http instead). Thanks! – hcpl Feb 28 '14 at 12:46
  • 13
    npm install npm -g also gives me the error SELF_SIGNED_CERT_IN_CHAIN – Anders Bornholm Feb 28 '14 at 14:34
  • I have the same problem as Anders Bornholm, so no dice with updating the npm – Karvapallo Feb 28 '14 at 15:22
  • Also the same problem as Anders Bornholm. And I just installed nodejs through brew. – Cereal Feb 28 '14 at 15:28
  • 3
    If this doesn't work, do `npm config set ca ""` first, then upgrade, then undo the config change. See: http://stackoverflow.com/a/22099006/106302 – We Are All Monica Feb 28 '14 at 15:46
  • Do we need `sudo` for `-g`? – Redsandro Feb 28 '14 at 16:04
  • 1
    @Redsandro `sudo` changes the user, `-g` flag sets if to install globally for that user or just in local `node_modules`. – Radek Feb 28 '14 at 16:57
  • I updated node itself using ```sudo n stable``` and it fixed the issue for me. – svassr Feb 28 '14 at 20:52
  • `npm update` failed silently doing nothing, outputting nothing, as they say in the source now, use `npm install -g --ca ""` – TWiStErRob Feb 28 '14 at 21:47
  • On Windows, my version of Node was quite old (1.2.18) and I got stuck while self-updating npm due to a semver version (^2.2.1) mismatch. Just ended up installing the latest Node package and everything works fine now. – Ates Goral Mar 01 '14 at 03:49
80

For now I just switched registry URL from https to http. Like this:

npm config set registry="http://registry.npmjs.org/"
Hermann
  • 1,150
  • 8
  • 9
  • 1
    Worked like a charm for me. I didn't want to lose the original CA or force it to ignore SSL errors. – SnowInferno Jan 07 '14 at 00:33
  • 28
    Disabling security can't be the solution! – Alessandro Pezzato Feb 28 '14 at 19:55
  • 1
    I had previously used this, but for some reason switching it back to 'https://' from 'http://' made mine work again. – kshreve Jan 23 '15 at 12:34
  • After trying all other solution, this work for me finally :-) – Swapnil Kadu Sep 25 '18 at 15:29
  • I didn't want to turn off the checking of certs completely so tried this one. Worked but I have the same concern, so now we're pulling packages on an unsecured connection. I understand that this has nothing to do with Node, this is the problem I'm getting because of our proxy but still ... kind of crazy – Laszlo T Nov 15 '18 at 16:16
  • That is causing an issue with my intranet firewall auth portal. See [my answer here](https://unix.stackexchange.com/a/647828/398728): I had to remove this settings with `npm config rm registry` and use `npm set strict-ssl false` instead. –  May 03 '21 at 10:31
52

The error SELF_SIGNED_CERT_IN_CHAIN means that you have self signed certificate in certificate chain which is basically not trusted by the system.

If that happens, basically something fishy is going on, therefore as people already commented, it is not recommended to just disable certificate checks, but better approach is to understand what is the problem and fix the cause of it.

This maybe related either to:

  • custom repository address which doesn't have the right certificate,

  • a corporate network with transparent proxy.

    If you're behind a corporate web proxy, you should set-up the proper HTTP_PROXY/HTTPS_PROXY environment variables or set them via npm:

      npm config set proxy http://proxy.company.com:8080
      npm config set https-proxy http://proxy.company.com:8080
    

    See: How to setup Node.js and Npm behind a corporate web proxy

If you trust the host, you can export the self-signed certificate from the chain and import them into system, so they're marked as trusted.

This can be achieved by checking the certificates by (change example.com into npm repo which is failing based on the npm-debug.log):

openssl s_client -showcerts -connect example.com:443 < /dev/null

then save the certificate content (between BEGIN and END) into .crt file in order to import it.

Linux

As per suggestion, you can add the below to the /etc/environment file (Node 7.4+) to export your CA chain, like:

NODE_EXTRA_CA_CERTS=/etc/pki/ca-trust/source/anchors/yourCer‌​ts.pem

CentOS

On CentOS 5 this can be appended into /etc/pki/tls/certs/ca-bundle.crt file, e.g.

ex +'g/BEGIN CERTIFICATE/,/END CERTIFICATE/p' <(echo | openssl s_client -showcerts -connect example.com:443) -scq | sudo tee -a /etc/pki/tls/certs/ca-bundle.crt
sudo update-ca-trust force-enable
sudo update-ca-trust extract
npm install

Note: To export only first certificate, remove g at the beginning.

In CentOS 6, the certificate file can be copied to /etc/pki/ca-trust/source/anchors/.

Ubuntu/Debian

In Ubuntu/Debian, copy CRT file into /usr/local/share/ca-certificates/ then run:

sudo update-ca-certificates

macOS

In macOS you can run:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/foo.crt

Windows

In Windows: certutil -addstore -f "ROOT" new-root-certificate.crt


See also: npm - Troubleshooting - SSL Error

Elijah Lynn
  • 12,272
  • 10
  • 61
  • 91
kenorb
  • 155,785
  • 88
  • 678
  • 743
  • 2
    > If that's the case, you need to export the self-signed certificate from the chain and import them into system, so they're marked as trusted. - Makes trick for me. – dmi3y Jul 12 '16 at 17:48
  • 3
    Great! It also helps to add NODE_EXTRA_CA_CERTS=/etc/pki/ca-trust/source/anchors/yourCerts.pem to the /etc/environment. Node 7.4+ takes this into account – ph4r05 Sep 06 '17 at 14:09
  • 3
    This is the only correct answer here. The rest is just an unsafe workaround... – Nickon Jul 31 '20 at 11:00
  • @ph4r05 I did the same with ~/.zshrc on Mac: `export NODE_EXTRA_CA_CERTS=/path-to-cert/yourCerts.pem` – Rotem Dec 16 '20 at 10:49
50
npm config set strict-ssl false -g

To save it globally

Andy
  • 49,085
  • 60
  • 166
  • 233
Robin
  • 6,879
  • 7
  • 37
  • 35
  • Doing this gives me the infamous `cb() never called!` npm error – Jeremy Apr 04 '19 at 13:23
  • After this setting, I'm geeting below error npm ERR! code E401 npm ERR! Unable to authenticate, need: Negotiate, NTLM npm ERR! A complete log of this run can be found in: npm ERR! C:\BuildAgent\npm-cache\_logs\2019-06-24T10_23_46_563Z-debug.log – Shami Qureshi Jun 24 '19 at 10:24
  • 1
    Disabling security is an inherently bad idea. Please don't do this. – CWSites Mar 14 '23 at 20:26
31

You need to upgrade npm.

// Do this first, or the upgrade will fail
npm config set ca ""

npm install npm -g

// Undo the previous config change
npm config delete ca

You may need to prefix those commands with sudo.

Source: http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more

We Are All Monica
  • 13,000
  • 8
  • 46
  • 72
  • @Oliver Salzburg: re. your edit: on OS X I don't think `sudo` is required at all, and only prefixing the upgrade command with `sudo` worked fine for me. YMMV. – We Are All Monica Feb 28 '14 at 15:48
  • Ah, this worked for me. Thanks for the specific instructions on undoing the config change (so I didn't have to dig it up myself)! – Matt Feb 28 '14 at 16:16
  • Interesting. I only made the edit after having tested this on a Debian server. I like the current revision though ;) – Oliver Salzburg Feb 28 '14 at 16:18
  • Ubuntu/Debian require additional linking, see my answer below. – Redsandro Feb 28 '14 at 16:26
  • 3
    This should be the accepted solution. This does not disable security and is the "official" solution desribed in npm blog. – Alessandro Pezzato Feb 28 '14 at 19:59
  • This works regardless. My setup is Ubuntu 13.10. I used NVM to install node (and the NPM version it came with). NPM version was 1.4.3 when i ran into this issue. Followed the instructions in this answer and all went well. Thanks jnylen. – Kyle Feb 28 '14 at 23:02
  • Unfortunately, if you're on an older version of node (such as Ubuntu 12.04 LTS) then upgrading npm like this will break it. – Jon Watte Sep 17 '14 at 16:25
  • `NODE_EXTRA_CA_CERTS ` is very helpful! – tertek Jul 06 '22 at 14:31
21

Putting this before the command seems to work NODE_TLS_REJECT_UNAUTHORIZED=0. ex: NODE_TLS_REJECT_UNAUTHORIZED=0 npm ...

It would be best to figure out how to make node see self signed certificate as valid. strict-ssl suggestion above didn't work for me for some reason. If you understand the security implications and need a temporary quick fix, this is what I found in some random github issues during Google search of the error.

Adam Lane
  • 1,784
  • 19
  • 25
  • 3
    for Windows, use "set NODE_TLS_REJECT_UNAUTHORIZED=0". And then works like a charm !! – Tarun Varshney Jun 24 '19 at 11:30
  • It works :) `Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.` – Saikat Mar 29 '21 at 09:26
8

The repository no longer supports self-signed certificates. You need to upgrade npm.

// Disable the certificate temporarily in order to do the upgrade
npm config set ca ""

// Upgrade npm. -g (global) means you need root permissions; be root 
// or prepend `sudo`
sudo npm install npm -g

// Undo the previous config change
npm config delete ca

// For Ubuntu/Debian-sid/Mint, node package is renamed to nodejs which 
// npm cannot find. Fix this:
sudo ln -s /usr/bin/nodejs /usr/bin/node

You need to open a new terminal session in order to use the updated npm.

Source: This was originally an edit on jnylen's answer. Although the guidelines say "We welcome all constructive edits, but please make them substantial," the edit was rejected due to "This edit changes too much in the original post; the original meaning or intent of the post would be lost." I guess the community prefers a separate answer.

Redsandro
  • 11,060
  • 13
  • 76
  • 106
  • This worked for me. However I didn't need the last command: `sudo ln -s /usr/bin/nodejs /usr/bin/node`. – absynce Feb 28 '14 at 23:42
  • 1
    It probably depends on whether you installed from the official Ubuntu repositories, a third party repository (for a newer version), or compiled yourself (for newest version). – Redsandro Mar 28 '14 at 13:28
8

just for development in windows

$Env:NODE_TLS_REJECT_UNAUTHORIZED=0 
jiz
  • 308
  • 3
  • 7
  • just a small detail - this is a script to run from Powershell console. And then run "npm i" within the same PowerShell window. – Yura Oct 08 '21 at 13:14
7

For those who on a mac with the same issue and installed npm via homebrew:

brew uninstall npm

then

brew install npm

Works for me on osx (10.9.1)

EDIT: You may need to brew update before installing npm. You can also do a brew upgrade after updating homebrew. Also it might be helpful to run brew doctor if you run into any other issues.

Patrick
  • 555
  • 1
  • 5
  • 13
6

I've created an article how to disable most npm problems behind a corporate firewall if you're out of options.

Be aware that you might be vulnerable to attacks.

https://wnderlvst.com/stories/102a237a-cea1-463b-89db-82224f1c1cbe

Powershell

yarn config set "strict-ssl" false
yarn config set "network-timeout" 600000
$env:NODE_TLS_REJECT_UNAUTHORIZED=0
TheDomis4
  • 122
  • 1
  • 13
4

Quick and clean solution (linux tested) (After fatidic February 27, 2014)


Uninstall npm

npm rm npm -g

Install npm (new URL is www.npmjs.org instead npmjs.org)

curl https://www.npmjs.org/install.sh | sh

Tip: how to install node.js in linux https://stackoverflow.com/a/22099363/333061

Community
  • 1
  • 1
Igor Parra
  • 10,214
  • 10
  • 69
  • 101
  • The command doesn't work anymore due to a redirect 301 but you can still type ```https://www.npmjs.org/install.sh``` in your browser and download it before running it manually. – svassr Feb 28 '14 at 21:30
  • Or run curl with the [-L flag](http://curl.haxx.se/docs/faq.html#How_do_I_tell_curl_to_follow_HTT) – Evan Cordell Feb 28 '14 at 21:46
  • previous `curl https://npmjs.org/install.sh` command is redirecting to `https://www.npmjs.org/install.sh` that's why `curl https://www.npmjs.org/install.sh | sh` works seamless. is OK to install from now on little padawan. :) – Igor Parra Mar 01 '14 at 00:39
2

Uninstall NPM and install it again.

As of February 27, 2014 npm no longer supports its self-signed certificates. http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more

The link above suggests upgrading NPM using NPM. This also fails with SELF_SIGNED_CERT_IN_CHAIN...

Florian Winter
  • 4,750
  • 1
  • 44
  • 69
2

Turning off SSL seems like a profoundly bad idea. npm's blog explains that they no longer support their self-signed cert. They suggest upgrading npm via npm install npm -g, but I of course got the same SELF_SIGNED_CERT_IN_CHAIN error. So I just updated node, which updated npm along with it. Exact procedure depends on how you installed node in the first place.

Jeremiah Orr
  • 2,620
  • 1
  • 18
  • 24
2

You will need to find the proxy details of your company and the npm registry that you should be using. After that you can specify the same in .npmrc file located under user folder C:/users/<your_user>.

this is how it can be specified -

registry=https://your_company/npm/registry/
proxy=http://username:password@proxy:port/
https-proxy=http://username:password@proxy:port/

The password is in plain text which is obviously not ideal may be there is a way to encrypt it in a way that npm understands.

somshivam
  • 759
  • 7
  • 19
2

For people who are struggling with getting a ca-file:

  1. Go to https://registry.npmjs.org/
  2. Open the used certificate: enter image description here

3. Click Details, then export and save it as a (*.pem, *.crt) file

  1. Then add this file to npm config npm config set cafile "C:\Users\YOU\nameOfCert.crt"

Hope this saves someone of you some minutes/hours :)

lennoxGER
  • 284
  • 1
  • 6
0

For me this was a super simple solution. All I needed to do was set the https-proxy in npm via npm config set https-proxy "http://proxyserverurl:port". @somshivam 's solution works too, but if you're going to have the module installed by a cloud pipeline like Azure DevOps, you can't have the proxy setting in the npmrc file or it will fail.

billoverton
  • 2,705
  • 2
  • 9
  • 32
  • How to fix this in Auzre DevOps? npm config set https-proxy "http://proxyserverurl:port this didn't work for me, still same error. – Xiaolong Jun 23 '23 at 16:21
  • Can you share exact error and what you are doing when you receive it? For me this was an issue only on local (as Azure DevOps VM is not going through the corporate proxy). If you are receiving this error while running the DevOps pipeline it may be a different issue. Happy to help here but you may want to create a new SO Question instead of trying to address through these comments. – billoverton Jul 10 '23 at 14:01
-1

I bypass this error with:

const https = require('https')

const agent = new https.Agent({
  rejectUnauthorized: false,
})

In request, I pass:

httpsAgent: agent,

like:

await axios.get(options.url, {
    httpsAgent: agent,
    headers: options.headers,
    data: options.data
});
Ibrahim Hammed
  • 833
  • 1
  • 8
  • 17
-3

I was having the same SSL self signed cert error because of corporate proxy. I was having issue while installing node-gyp. I tried uninstalling Angular/cli first and installing node-gyp and then try reinstalling Angular cli

npm uninstall -g @angular/cli
npm install -g node-gyp
npm install -g @angular/cli

It worked perfectly