likes
comments
collection
share

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

作者站长头像
站长
· 阅读数 9

关于安装 node-Sass 报错的解决记录(转载的,侵删)

问题

新建 项目后 yarn 或 npm install 命令的时候,node-sass报错了

解决

  • 查看 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

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

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

2. node-sass: Command failed

如果遇到错误 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. error in ./resources/assets/sass/app.scss

如果遇到错误

4. 无法执行命令

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

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

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

5. 如果遇到 cross-env 报错

`npm i -g cross-env`

6. 其他情况

如果仍然不能下载 参考文章:www.jianshu.com/p/4609564e3… 参考 issue:github.com/yarnpkg/yar…

创建 .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"

版本对照

NodeJS  | Supported node-sass version | Node Module
--------|-----------------------------|------------
Node 20 | 9.0+                        | 115
Node 19 | 8.0+                        | 111
Node 18 | 8.0+                        | 108
Node 17 | 7.0+, <8.0                  | 102
Node 16 | 6.0+                        | 93
Node 15 | 5.0+, <7.0                  | 88
Node 14 | 4.14+, <9.0                 | 83
Node 13 | 4.13+, <5.0                 | 79
Node 12 | 4.12+, <8.0                 | 72
Node 11 | 4.10+, <5.0                 | 67
Node 10 | 4.9+, <6.0                  | 64
Node 8  | 4.5.3+, <5.0                | 57
Node <8 | <5.0                        | <57

引用:www.jianshu.com/p/89f5e094b…

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