如何解决sass-loader和node-sass版本冲突的问题

 更新时间:2022年04月11日 09:58:04   作者:胡庚申  
这篇文章主要介绍了如何解决sass-loader和node-sass版本冲突的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

太难了,两天没有学习了,这个问题卡了很久,差点就放弃了,今天终于解决了,继续学习Vue!

报错信息1

ERROR  Failed to compile with 6 errors                                                                                    7:45:21 PM

 error  in ./src/components/advanceDemo/toastCom.vue?vue&type=style&index=0&id=6f04d134&lang=scss&scoped=true&

Syntax Error: TypeError: this.getOptions is not a function

报错信息2

1 error generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/goldwater/Documents/vue/vue3.0-demo/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 20.2.0
gyp ERR! command "/usr/local/bin/node" "/Users/goldwater/Documents/projectCode/project-learning-repository/vue/vue3.0-demo/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/goldwater/Documents/vue/vue3.0-demo/node_modules/node-sass
gyp ERR! node -v v16.6.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN vue-loader@16.4.1 requires a peer of @vue/compiler-sfc@^3.0.8 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@8.0.2 requires a peer of sass@^1.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN sass-loader@8.0.2 requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.14.1 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.14.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/goldwater/.npm/_logs/2021-08-06T12_04_18_807Z-debug.log

解决办法

时代在发展,更新换代很快,作为一个前端小白在网上找了很多方法,最后还是请教一位老司机,解决了问题,下面说一下我解决的过程,让后人成功避开

首先要先把上网环境解决了,在~/.npmrc添加以下镜像:

phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=https://registry.npm.taobao.org

网上解决方法

去官方的github仓库去寻找合适的版本

node-sass: https://github.com/sass/node-sass/tags

sass-loader: https://github.com/webpack-contrib/sass-loader/tags

npm uninstall sass-loader node-sass    //卸载
npm install sass-loader@7.3.1 node-sass@4.14.1  --save-dev  //安装对应的版本

最后,还是失败了。

我的解决方案

执行以下脚本:

npm uninstall sass-loader node-sass
npm install sass-loader@8.0.2 sass@1.26.5  --save-dev

不要安装node-sass,安装sass就可以了,package.json如下:

{
  "name": "vue3.0-demo-1",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "joi": "^17.4.2",
    "vue": "^2.6.11"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^7.15.0",
    // 这两个是重点:sass、sass-loader
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "vue-template-compiler": "^2.6.11"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ]
}

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • vue中ref和reactive的区别及说明

    vue中ref和reactive的区别及说明

    这篇文章主要介绍了vue中ref和reactive的区别及说明,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-08-08
  • Vue二次封装axios为插件使用详解

    Vue二次封装axios为插件使用详解

    这篇文章主要介绍了Vue二次封装axios为插件使用详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-05-05
  • Vue封装远程下拉框组件的实现示例

    Vue封装远程下拉框组件的实现示例

    本文主要介绍了Vue封装远程下拉框组件的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-07-07
  • VUE element-ui 写个复用Table组件的示例代码

    VUE element-ui 写个复用Table组件的示例代码

    本篇文章主要介绍了VUE element-ui 写个复用Table组件的示例代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-11-11
  • 浅析vue数据绑定

    浅析vue数据绑定

    本文主要介绍了vue数据绑定的相关知识,具有一定的参考价值,下面跟着小编一起来看下吧
    2017-01-01
  • vue3+el-select实现触底加载更多功能(ts版)

    vue3+el-select实现触底加载更多功能(ts版)

    这篇文章主要给大家介绍了基于vue3和el-select实现触底加载更多功能,文中有详细的代码示例,感兴趣的同学可以借鉴参考下
    2023-07-07
  • vue更多筛选项小组件使用详解

    vue更多筛选项小组件使用详解

    这篇文章主要为大家详细介绍了vue更多筛选项小组件的使用方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-06-06
  • 详解Vue之计算属性

    详解Vue之计算属性

    这篇文章主要介绍了Vue之计算属性的相关知识,文中讲解非常细致,代码帮助大家更好的理解和学习,感兴趣的朋友可以了解下
    2020-06-06
  • vue路由跳转了但界面不显示的问题及解决

    vue路由跳转了但界面不显示的问题及解决

    这篇文章主要介绍了vue路由跳转了但界面不显示的问题及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-04-04
  • vue项目中vue.config.js文件详解

    vue项目中vue.config.js文件详解

    vue.config.js 是一个可选的配置文件,如果项目的 (和 package.json 同级的) 根目录中存在这个文件,那么它会被 @vue/cli-service 自动加载,这篇文章主要介绍了vue项目中vue.config.js文件的介绍,需要的朋友可以参考下
    2024-02-02

最新评论