发布于 4年前

Angular CLI使用淘宝npm镜像新建项目失败

Angular CLI切换为淘宝的npm镜像cnpm后新建项目总是报网络错误:

$ ng new demo --style=scss --routing
create demo/e2e/app.e2e-spec.ts (287 bytes)
create demo/e2e/app.po.ts (208 bytes)
create demo/e2e/tsconfig.e2e.json (235 bytes)
create demo/karma.conf.js (923 bytes)
create demo/package.json (1317 bytes)
create demo/protractor.conf.js (722 bytes)
create demo/README.md (1021 bytes)
......
Installing packages for tooling via cnpm.
[npminstall:get] retry GET https://registry.npm.taobao.org/webpack-sources/%3E%3D1.1.0%20%3C2.0.0 after 100ms, retry left 4, error: ResponseError: socket hang up (req "error"), GET https://registry.npm.taobao.org/webpack-sources/%3E%3D1.1.0%20%3C2.0.0 -1 (connected: true, keepalive socket: true, agent status: {"createSocketCount":16,"createSocketErrorCount":0,"closeSocketCount":1,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":170,"freeSockets":{},"sockets":{"cdn.npm.taobao.org:443:::::::true:":5,"registry.npm.taobao.org:443:::::::true:":10},"requests":{"registry.npm.taobao.org:443:::::::true:":83}})
headers: {}

切换为npm官方镜像后成功。

ng set --global packageManager=npm

参考:Angular CLI设置npm镜像

©2020 edoou.com   京ICP备16001874号-3