解决sass-loader和node-sass版本冲突问题(太难了)_胡金水的博客-CSDN博客 ---- 解决思路正确 ---- node升级带来node-sass问题 ---- 问题已解决

解题思路
以往能用的时候 node 与 node-sass 配合,当打破后,大概会存在问题

  1. node(升级到16.xx.xx) 与 node-sass 不匹配
  2. node-sass (升级后) 与 sass-loader 不匹配
  3. sass-loader (升级后) 与 webpack 不匹配, 主要表现为
npm ERR! Conflicting peer dependency: webpack@5.66.0
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.36.0 || ^5.0.0" from sass-loader@8.0.2
npm ERR!   node_modules/sass-loader
npm ERR!     dev sass-loader@"8.0.2" from the root project

正解为 不用 node-sass 直接改用 sass ,再匹配sass 与 sass-loader就可以

node-sass -> sass

"sass": "^1.43.4",
"sass-loader": "^7.3.1",

npm uninstall node-sass
yarn add 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  //安装对应的版本

分隔线

最后,还是失败了。

---- 20220115 我再试了一下别的项目,总结一下解决,把 node-sass 干了,就用 sass , sass-loader,不要直接用别人指定的版本号,这个很重要
所以,比较通用的命令为,让yarn帮你定版本


npm uninstall node-sass
yarn add sass 
yarn add sass-loader

我的解决方案:---- 只供参考,不一定能解决你的问题

执行以下脚本:

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"
  ]
}

原网址: 访问
创建于: 2021-11-11 16:16:15
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论