9

node-sass踩坑记录 - 搞搞震

 2 years ago
source link: https://www.wujingquan.com/posts/a6b811ab.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Warning: LibSass and Node Sass are deprecated.
While they will continue to receive maintenance releases indefinitely, there are no
plans to add additional features or compatibility with any new CSS or Sass features.
Projects that still use it should move onto
Dart Sass.

Dart Sass 冲冲冲!

Node Sass 迁移至 Dart Sass

TODO…

方案一:在线安装(修改下载源)

修改下载源方案,将会在 npm install 的时候到设定的镜像站下载对应的二进制文件。

修改下载源站的方式有如下几种:

  • 修改 .npmrc 文件(仅当前项目有效)
  • 修改 npm 的配置(全局有效)

方式一:仅对当前项目指定某个镜像站

仅对当前项目有效

修改项目根目录下的 .npmrc 文件

// .npmrc

sass_binary_site=https://npmmirror.com/mirrors/node-sass

方式二:安装时指定某个镜像站

仅当次 npm install 有效

npm install node-sass --sass_binary_site="https://npmmirror.com/mirrors/node-sass"

方式二:npm全局指定某个镜像站

每次 npm install 有效

npm config set sass-binary-site https://npmmirror.com/mirrors/node-sass

方式三:设置系统环境变量

每次 npm install 有效

// Linux
SASS_BINARY_SITE=https://npmmirror.com/mirrors/node-sass

// Windows
set SASS_BINARY_SITE=https://npmmirror.com/mirrors/node-sass

方案二:离线安装(使用本地二进制文件)

方式一:修改npm配置

// npm
npm config set sass-binary-path e:/web/win32-x64-48_binding.node

// yarn
yarn config set sass-binary-path e:/web/win32-x64-48_binding.node

方式二:修改package.json

// package.json
"nodeSassConfig": {
  "binaryPath": "./lib/linux-x64-57_binding.node"
}

方式三:修改环境变量

// Windows
set SASS_BINARY_PATH=c:/win32-x64-46_binding.node

HTTP error 404 Not Found

检查 node-sass 版本与 Node.js 版本是否兼容。可以到Github的发布页面查看相关信息:https://github.com/sass/node-sass/releases

比方在 Node.js v10.24.1 环境下安装 node-sass v7.0.1,由于安装 node-sass 时会从镜像站中下载二进制文件,将会构造这样的URL地址进行访问下载: https://github.com/sass/node-sass/releases/download/v7.0.1/linux-x64-64_binding.node 该URL地址由以下几部分组成:

  • SASS_BINARY_SITE 默认情况下是 https://github.com/sass/node-sass/releases/download
  • node-sass version
  • process.platform 系统内核
  • process.arch 处理器架构
  • process.versions.modules Node.js 模块版本

但是由于 node-sass v7 不再兼容 Node.js v10,不会构建对应的二进制文件,即使构造了对应的URL去访问下载,但是由于资源不存在,所以就访问不到就出现404错误。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK