NodeJS 如何解决Angular-cli安装中的代码ERR_INVALID_URL

qvtsj1bj  于 2022-12-18  发布在  Node.js
关注(0)|答案(5)|浏览(964)

在我的windows-10中,我安装了:
节点js-v16.13.0
国家预防机制-v8.1.0
当我尝试运行npm install -g @angular/cli时
我得到这个错误:
npm错误!代码错误无效URL
npm错误!URL无效
我如何获得这种决心?
谢谢

hjqgdpho

hjqgdpho1#

我只是使用以下命令重新配置代理:

npm config set proxy http://username:password@host:port

而且成功了!

qv7cva1a

qv7cva1a2#

通常会有一个与此消息关联的日志文件:

npm ERR! code ERR_INVALID_URL
npm ERR! Invalid URL

**npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\....\AppData\Local\npm-cache\_logs\2021-11-04T09_13_08_065Z-debug.log**

你可以在这个文件中看到更多的细节。我也有同样的问题,在我的例子中,我只是在最初设置代理时省略了“http://”:

npm config set proxy "**http://**127.0.0.1:3128/"
             here !!! ^^^^^^^

作为参考,它失败并显示以下跟踪:

39 verbose stack TypeError [ERR_INVALID_URL]: Invalid URL
39 verbose stack     at new NodeError (node:internal/errors:371:5)
39 verbose stack     at onParseError (node:internal/url:552:9)
39 verbose stack     at new URL (node:internal/url:628:5)
39 verbose stack     at getProxyUri (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:147:53)
39 verbose stack     at getAgent (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:20:17)
39 verbose stack     at remoteFetch (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\remote.js:31:17)
39 verbose stack     at cacheFetch (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\cache\index.js:15:28)
39 verbose stack     at async fetch (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\fetch.js:82:7)
39 verbose stack     at async Arborist.[nodeFromEdge] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:1061:19)
39 verbose stack     at async Arborist.[buildDepStep] (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist\lib\arborist\build-ideal-tree.js:930:11)

ztigrdn8

ztigrdn83#

通过添加https_proxy=http://username:password@host:port更新npmrc文件此外,您可能还需要添加strict-ssl=false

pcww981p

pcww981p4#

我只要运行所有这些命令

npm config rm proxy
npm config rm https-proxy
npm config delete proxy
npm config delete https-proxy
npm config --global rm proxy
npm config --global rm https-proxy
npm config set registry "http://registry.npmjs.org"
npm config set strict-ssl false

我用顺风,所以我只是跑

npm install 
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init

这是我的工作

vlf7wbxs

vlf7wbxs5#

最近我也遇到了同样的问题,我运行了npm config ls -l,注意到我们使用的npm存储库的设置格式不正确:

; "project" config from C:\MyPackage\.npmrc

@intercede-free:registry = "\"https://npm.pkg.github.com/"

更正文件中设置URL不正确的设置修复了我的问题。

相关问题