node.js - “npm help update”(在 Windows 中)给出无效 URL 错误
问题描述
我有 nodejs v16.13.0 和 npm 8.1.0。
当我npm help update
在 cmd 或 PowerShell(管理员和普通)中运行命令时,出现以下错误
npm help update
npm ERR! Invalid URL: file://C:%5CProgram%20Files%5Cnodejs%5Cnode_modules%5Cnpm%5Cdocs%5Coutput%5Ccommands%5Cnpm-update.html
我可以确认该文件存在于该位置,但由于某种原因,该命令未正确读取路径。是否有我需要更改的文件?
我还没有在网上找到任何相关的解决方案......到目前为止,这里也没有。
解决方案
我对所有 npm help ... 命令都有同样的问题,例如:
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
似乎存在编码 URL 的问题,因为文件本身存在。如果 URL 解码成
file:///C:/Users/mirek/AppData/Roaming/npm/node_modules/npm/docs/output/commands/npm.html
它可以在浏览器中打开,它工作得很好。另外,根据登录
C:\Users\mirek\AppData\Local\npm-cache\_logs\2021-11-04T06_20_51_613Z-debug.log
问题出在
C:\Users\mirek\AppData\Roaming\npm\node_modules\npm\lib\utils\open-url.js:31:11.
它试图验证文件 URL 是否正确。但是,它显然存在编码 URL 的问题。
因此,我尝试在该文件中注释第 7 行,该文件对 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')
修改后它工作得很好。
推荐阅读
- javascript - JavaScript Array 如何选择内容
- python - 如何取消 asyncio 的 loop.call_later()?
- python - 使用函数过滤 Tkinter Treeview 的显示
- c# - 在 c# 中将签名算法从 sha1 转换为 sha256
- javascript - Javscript:从数组中的对象(带有键和值)中删除大括号
- c# - ASP.NET ASYNC WAIT TASK 不处理多个请求
- android - 如何确保 Facebook 广告仅在从 Playstore 下载时才会显示?
- javascript - 将日期“2020 年 8 月 18 日星期二 12:30:44 GMT+0530”转换为“2020 年 8 月 18 日星期二 12:30:44 GMT+05:30”
- javascript - 我们可以在自适应卡片中添加多少个提及实体?
- vba - 我们可以通过名称访问单词表而不是使用 vba 索引吗?