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

问题

新建 laravel 项目后
yarnnpm install 命令的时候,总不尽人意

解决

  • 查看 npm 配置 npm config list

    1. 将 npm 源切换至淘宝源
      npm config set registry https://registry.npm.taobao.org

    2. 通过 npm 全局安装 yarn
      npm install -g yarn

      如果执行 yarn 命令遇到报错,请将 npm bin -g 所得的路径添加至 PATH 环境变量中。

  • 查看 yarn 配置 yarn config list

    1. 将 yarn 源切换至淘宝源
      yarn config set registry https://registry.npm.taobao.org
    2. 执行 yarn install alias yarn
  • 配置 nvm 相关镜像地址

    nvm node_mirror http://npm.taobao.org/mirrors/node/
    nvm npm_mirror http://npm.taobao.org/mirrors/npm/

** 参考 **

  1. 如果遇到错误 error An unexpected error occurred: “EINVAL: invalid argument, symlink

    请在你的执行命令之后添加 --no-bin-links
    e.g.
    yarn install –no-bin-links

  2. 如果遇到错误 error: xxxx node-sass: Command failed
    将 sass-binary-site 添加至 config 中

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

    指定 node-sass 从 npm 的淘宝源中下载。

  3. 如果任然不能下载
    参考文章:www.jianshu.com/p/4609564e31dc
    参考 issue:github.com/yarnpkg/yarn/issues/526...

创建 .yarnrc 文件,并放置在项目中

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

sass_binary_site="https://npm.taobao.org/mirrors/node-sass/"
phantomjs_cdnurl="http://cnpmjs.org/downloads"
electron_mirror="https://npm.taobao.org/mirrors/electron/"
sqlite3_binary_host_mirror="https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror="https://npm.taobao.org/mirrors/node-inspector/"
chromedriver_cdnurl="https://cdn.npm.taobao.org/dist/chromedriver"
  1. 如果遇到错误

    ERROR Failed to compile with 2 errors 11:10:34
    error in ./resources/assets/sass/app.scss

    1. 检查你使用的源是否更换,当然可以选择使用代理 :joy:
    2. 检查 sass-binary-site 是否指定
    3. 执行 yarn install --force node-sass npm 对应的是 npm rebuild node-sass

    我习惯直接 yarn install --force 将整个重新进行构建

  2. 如果你使用 yarn 安装了 vue 这样的 cli 工具。然后无法执行命令。请将 yarn global bin 添加至 PATH 环境变量中。

  3. 如果遇到 cross-env 报错
    npm i -g cross-env

若任然无法安装 node-sass ,可手动指定环境变量 SASS_BINARY_PATH,windows 参考如下:

SASS_BINARY_PATH 环境变量配置

引用:www.jianshu.com/p/89f5e094b8ce

如果提示无权限保存二进制文件,可执行 npm install --unsafe-perm

注意

因为本文章是所有流程执行完了才写的,所以可能遇到错误的顺序不对应,如果有什么不对的请指出,让我们一起帮助没遇到过的人解决他们的错误,让他们更便利的进行开发。因为使用的 yarn ,所以对应的 npm 的指令可能没有贴出,如果你发现了,请指出来。谢谢 :kissing_heart:

本作品采用《CC 协议》,转载必须注明作者和本文链接
Study hard and make progress every day. Study hard and make progress every day.
本帖由系统于 7年前 自动加精
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 19
mouyong

@iwzh 嗯呢。

7年前 评论

恩,node-sass安装总是出错,这下解决了

7年前 评论
mouyong

@YuxiangDong :smile: 恭喜啦

7年前 评论
medz

终其原因还是「墙」的问题,多搭梯子吧。

7年前 评论

因为 windows 下执行这个总是出问题,然后只能无奈地转战大 Mac 战场。:joy:

7年前 评论
mouyong

@medz 我也不知道,墙翻了,但不知道为什么命令行好像不走墙,不知道是不是错觉

7年前 评论
mouyong

@JokerLinly 我的是 win 和 Ubuntu 环境,你遇到过什么问题?如果有遗漏的,我尽力补上:joy: 我每次装 laravel,会遇到的基本是这几个。每次都要 google 比较尴尬

7年前 评论
medz

@蜗牛 不是错觉,命令行不走网页代理那一套。单独设置需要。

7年前 评论
mouyong

@medz :grin: 可否有篇文章介绍下如何做?:joy: 在 Ubuntu 中查过,试过,没成功过,我也不知道为什么不成功。能否容许我捡个现成的呀?

7年前 评论
medz

@蜗牛 ?我用Mac 手动设置系统 socket 代理的

7年前 评论
mouyong

@medz 尴尬了 :sweat_smile: 不过谢啦

7年前 评论
王老板的前端

我的哥, windows 10 ,yarn 按照方法来,已经解决.特来感谢...:lips:

7年前 评论
mouyong

@medz 找到解决办法了。命令行翻墙的。https://github.com/shadowsocks/shadowsocks...

7年前 评论
shijf

特来感谢

6年前 评论

@蜗牛 win 就没办法了

6年前 评论
mouyong

@lovecn 我能告诉你我是 windows 和 linux 一起用的吗?

6年前 评论
mouyong

@lovecn 你是windows 的话。是怎么操作的呢?是否有试过

rm -rf node_modules
yarn config set sass-binary-site https://npm.taobao.org/mirrors/node-sass
yarn config set registry https://registry.npm.taobao.org

我是这样一般都可以的,如果不可以具体报错是什么呢?

6年前 评论

如果yarn install --no-bin-links 后执行 npm run watch-poll 报错,可以查看resources/sass/app.scss 将里面的除bootstrap的引入其他全部删除就可以了

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
打杂的 @ 某某医学
文章
35
粉丝
63
喜欢
328
收藏
113
排名:37
访问:19.1 万
私信
所有博文
社区赞助商