npm ,yarn 更换使用国内镜像源,阿里源,清华大学源

背景

在平时开发当中,我们经常会使用 Npm,yarn 来构建 web 项目。但是npm默认的源的服务器是在国外的,如果没有梯子的话。会感觉特别特别慢,所以,使用国内的源是非常有必要的。

img

Nnpm, yarn 常用命令

常用命令:
功能/工具名称 yarn npm
安装全部依赖 yarn / yarn install npm install
添加一个/多个依赖 yarn add xx npm install xx
删除一个/多个依赖 yarn remove npm uninstall
搜索 package 包 / npm search
yarn

Yarn 是由 Facebook、Google、Exponent 和 Tilde 联合推出了一个新的 JS 包管理工具 。

安装:
npm install -g yarn

执行 yarn xxx 命令报以下错误时:

img

操作以下步骤进行策略更改:

  1. 使用管理员身份运行 cmd 或 Power shell
  2. 输入:set-executionpolicy remotesigned
  3. 输入”Y“,回车保存

npm,yarn 使用国内源

原淘宝 npm 域名即将停止解析!!使用老域名的请尽快更新到新域名!

《淘宝 NPM 镜像站喊你切换新域名啦》
https://npm.taobao.orghttps://registry.npm.taobao.org 将在 2022.06.30
号正式下线和停止 DNS 解析。

域名切换规则:

https://npm.taobao.org => https://npmmirror.com
https://registry.npm.taobao.org => https://registry.npmmirror.com

yarn 配置源:

有两种方式,一种是临时配置的,一种是永久配置的

临时使用

如果只是一次性使用,可以使用下面的命令

npm --registry https://registry.npm.taobao.org install XXX(模块名)
全局配置

这种设置是全局的,以后每次都会自动读取已经设置好的源

    // 查询源
    yarn config get registry

    // 更换国内源
    yarn config set registry https://registry.npmmirror.com

    // 恢复官方源
    yarn config set registry https://registry.yarnpkg.com

    // 删除注册表
    yarn config delete registry
npm 配置源:

注意 npm 更换国内镜像源之后,将无法再使用 npm search
命令,需要恢复为官方源才可以使用,如果恢复官方源后还不可使用,运行删除注册表命令后重试即可。

    // 查询源
    npm config get registry

    // 更换国内源
    npm config set registry https://registry.npmmirror.com

    // 恢复官方源
    npm config set registry https://registry.npmjs.org

    // 删除注册表
    npm config delete registry

posted on   静以修身俭以养德  阅读(2152)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· DeepSeek “源神”启动!「GitHub 热点速览」
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
历史上的今天:
2015-10-08 EntityFramework执行SQL语句
2015-10-08 Asp.net mvc + .net ef database first 或 model first 时如何添加验证特性
2015-10-08 partial类与[MetadataType(typeof(类名))]有什么区别?
2015-10-08 Entity Framework 学习总结之一:ADO.NET 实体框架概述
2014-10-08 acdsee 15中文版的许可证密钥+激活方法
2011-10-08 Session丢失的解决办法小结

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示