Yarn 也敌不过的网络问题

栏目: Node.js · 发布时间: 6年前

内容简介:当你兴高采烈地下载完 Git 仓库中的项目,端起红茶,敲下这时候我就想起一句名言有时生活就像石头,会给你迎头一击。 —— 乔布斯

当你兴高采烈地下载完 Git 仓库中的项目,端起红茶,敲下 yarn 准备开发。不久后你就会发现满屏幕的 error

error \node_modules\node-sass: Command failed.

这时候我就想起一句名言

有时生活就像石头,会给你迎头一击。 —— 乔布斯

面对国内网络状况,使用 Yarn 也会出现依赖报错,多数原因是 node-sass 库下载、构建失败:

s3.amazonaws.com

方式一 创建 .npmrc

在代码根目录中创建 .npmrc 文件有助于项目开发人员根据自身环境对 npm 进行配置:

sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

registry=https://registry.npm.taobao.org

方式二 设置淘宝 NPM 镜像

通过命令的方式设置本机的 Yarn 配置文件,将仓库源服务器指向淘宝提供的镜像:

yarn config set registry https://registry.npm.taobao.org -g

yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g

#yarn config set sass-binary-site https://npm.taobao.org/mirrors/node-sass

方式三 使用代理

使用一个 HTTP/S 代理可以顺利地下载好依赖文件

yarn config set proxy http://127.0.0.1:1080

# 下载完成后删除 http 代理
yarn config delete proxy

参考资料

关于安装 node-Sass 报错的解决记录

安装 node-sass 的正确姿势

淘宝 NPM 镜像

npm的.npmrc文件在哪里?缓存及全局包文件在什么位置?


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

How to Solve It

How to Solve It

Zbigniew Michalewicz、David B. Fogel / Springer / 2004-03-01 / USD 59.95

This book is the only source that provides comprehensive, current, and detailed information on problem solving using modern heuristics. It covers classic methods of optimization, including dynamic pro......一起来看看 《How to Solve It》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器