美文网首页
# scss 的坑

# scss 的坑

作者: ted4kra | 来源:发表于2021-02-19 16:36 被阅读0次

    问题2更好的解决方案是这个

    Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x
    Found bindings for the following Environments: Linux 64-bit with Node.js 12.x

    以下是sass-loader的官方文档

    By default the loader resolve the implementation based on your dependencies. Just add required implementation to package.json (sass or node-sass package) and install dependencies.

    Example where the sass-loader loader uses the sass (dart-sass) implementation:
    package.json

    {
      "devDependencies": {
        "sass-loader": "^7.2.0",
        "sass": "^1.22.10"
      }
    }
    

    Example where the sass-loader loader uses the node-sass implementation:

    package.json

    {
      "devDependencies": {
        "sass-loader": "^7.2.0",
        "node-sass": "^5.0.0"
      }
    }
    

    也就是说,可以直接使用sass而不用node-sass
    所以直接删除掉node-sass,然后安装sass吧
    npm install sass sass-loader -D



    1. 项目中引入SCSS

      $ npm i sass-loader@10.x node-sass -D

      因为Vue环境用的是Vue@2.x ,如果直接安装sass-loader会安装11.x,该版本与Vue2.x不适配,可以装10.x

      node-sass自动安装,我本地是5.0.0

      -S 是 --save :安装在packages.json的dependencies下面 -D 是 --save-dev :安装在packages.json的devDependencies下面

    2. 安装好node-sass和sass-loader以后,重新跑项目,报以下错误

      Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x

      Found bindings for the following Environments: Linux 64-bit with Node.js 12.x

      node -v查看本地的node 版本就是12.x,但是sass-loader需要的是8.x

      如果本地有node.js的8.x版本,直接切换当前的node.js版本就行,使用N或者nvm

      如果本地没有

      1. 官网找到对应的版本,下载安装。
      1. $ npm rebuild sass-loader
      1. 重新运行项目

    相关文章

      网友评论

          本文标题:# scss 的坑

          本文链接:https://www.haomeiwen.com/subject/ufmaxltx.html