"npm help update" (in Windows) giving Invalid URL error

Viewed 1985

I have nodejs v16.13.0 and npm 8.1.0.

When I run the command npm help update in cmd or PowerShell (Admin and normal) I get the following error

npm help update
npm ERR! Invalid URL: file://C:%5CProgram%20Files%5Cnodejs%5Cnode_modules%5Cnpm%5Cdocs%5Coutput%5Ccommands%5Cnpm-update.html

I can confirm that the file exists at the location, but for some reason, the command is not reading the path correctly. Is there a file I need to make changes to?

I haven't found any relevant solution(s) on the web... and so far, not here either.

1 Answers

I have the same issue with all npm help ... commands, e.g.:

C:\DEV\youtube>npm help npm
npm ERR! Invalid URL: file://C:%5CUsers%5Cmirek%5CAppData%5CRoaming%5Cnpm%5Cnode_modules%5Cnpm%5Cdocs%5Coutput%5Ccommands%5Cnpm.html

npm ERR! A complete log of this run file:///C:/Users/mirek/AppData/Roaming/npm/node_modules/npm/docs/output/commands/npm.htmlcan be found in:
npm ERR!     C:\Users\mirek\AppData\Local\npm-cache\_logs\2021-11-04T06_20_51_613Z-debug.log

It appears ther is a problem with encoded URL, because the file itself exists. If URL decoded into

file:///C:/Users/mirek/AppData/Roaming/npm/node_modules/npm/docs/output/commands/npm.html

it can be opened in browser and it works just fine. Also, base on the log in

C:\Users\mirek\AppData\Local\npm-cache\_logs\2021-11-04T06_20_51_613Z-debug.log

the problem is in

C:\Users\mirek\AppData\Roaming\npm\node_modules\npm\lib\utils\open-url.js:31:11.

Which tries to validate if file URL correct. However, it has apparently problem with encoded URL.

Therefore I tried to comment line 7 in that file, which encodes URL:

5.    // attempt to open URL in web-browser, print address otherwise:
6:    const open = async (npm, url, errMsg) => {
7:      //url = encodeURI(url)
8:      const browser = npm.config.get('browser')

It works just fine after that modification.

Related