5

I have installed node.js But in command prompt npm command is not identified. I have set environmental variable also. Kindly help me out.

This is the response in command prompt:

C:\Users\593180.INDIA>npm
URIError: URI malformed
at decodeURIComponent (native)
at Url.parse (url.js:179:19)
at Object.urlParse [as parse] (url.js:101:5)
at Object.validateUrl [as validate] (C:\Program Files (x86)\nodejs\node_modu
les\npm\node_modules\nopt\lib\nopt.js:157:13)
at validate (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\nop
t\lib\nopt.js:205:24)
at validate (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\nop
t\lib\nopt.js:172:11)
at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\nopt\lib\nopt
.js:101:12
at Array.map (native)
at C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\nopt\lib\nopt
.js:67:15
at Array.forEach (native)
C:\Program Files (x86)\nodejs\node_modules\npm\lib\npm.js:37
throw new Error('npm.load() required')
      ^
Error: npm.load() required
at Object.npm.config.get (C:\Program Files (x86)\nodejs\node_modules\npm\lib
\npm.js:37:11)
at exit (C:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\error-hand
ler.js:49:27)
at process.errorHandler (C:\Program Files (x86)\nodejs\node_modules\npm\lib\
utils\error-handler.js:314:3)
at process.EventEmitter.emit (events.js:95:17)
at process._fatalException (node.js:272:26)
Dawson Loudon
  • 5,989
  • 2
  • 27
  • 31
Cherry
  • 505
  • 1
  • 5
  • 13

3 Answers3

8

You probably broke npm by configuring your proxy or other URL

Go into your user folder

C:\Users\username

edit the file ".npmrc"

and fix your proxy url or other corrupted url proxy = http://login:password@proxyaddress:port

amdev
  • 2,264
  • 3
  • 23
  • 40
  • Even after completely deleting the .npmrc file and uninstalling nodejs completely (even deleting manually the nodejs folder in program files),I still have this error – enissay Jul 27 '16 at 17:34
  • Looking up npmrc in the nodejs folder in the program files and deleting all of them fixed it for me – enissay Jul 27 '16 at 18:07
  • Why down vote ? I encountered this issue and my answer solved it. Ofc it's not magic, an URIError: URI malformed issue can have many origin, but a wrong ".npmrc" is the first place where you have to looking for ! – amdev Oct 05 '16 at 11:39
  • Very useful. On my company PC I also had to add ´strict-ssl=false´ before the two lines ´proxy´ and ´https-proxy´ – Benny Skogberg Oct 31 '19 at 08:51
1

Might be one of following cases. Mine was second case. check your proxy : npm config get proxy

  1. If you have special characters in username or password , replace those characters with percent-encode [https://r12a.github.io/app-conversion/][1]

Say your password is password#123 - Get encoded version using above link which is password%23123 .

  1. If you have set proxy once without percent encoding, there is chance that this is saved in ".npmrc" in /Users/username and is not being updated when you run set config again with proper encoded password. You can directly edit ".npmrc" in that case.
0

Here is what worked for me. I was getting the same URI malformed exception.

My original URI format looked like this (I structured the URI this way based off of a popular answer in this question):

http://{domain}%5{username}:{password}/{baseURI}:{port}
i.e. http://COUNTRY%5bobjohnson:pass123/test.websitename.com:8080

What fixed it for me was removing the domain part of it and the %5 part.

Therefore the .npmrc file looked like this when it started working:

proxy=http://bobjohnson:pass123/test.websitename.com:8080
https-proxy=http://bobjohnson:pass123/test.websitename.com:8080
Shn_Android_Dev
  • 652
  • 8
  • 18