vue项目安装scss常见报错处理方式

 更新时间:2022年09月23日 08:40:48   作者:隔壁丿老苏  
这篇文章主要介绍了vue项目安装scss常见报错处理方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

安装sass依赖

npm install --save-dev sass-loader
//sass-loader依赖于node-sass
npm install --save-dev node-sass

第一种:Module build failed: TypeError: this.getResolve is not a function

如果运行之后项目报错

Module build failed: TypeError: this.getResolve is not a function
    at Object.loader (C:\Users\DELL\Desktop\fantastic-macarons\node_modules\sass-loader\dist\index.js:52:26)
 
 @ ./node_modules/vue-style-loader!./node_modules/css-loader?{"sourceMap":true}!./node_modules/vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-469af010","scoped":true,"hasInlineConfig":false}!./node_modules/sass-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/components/HelloWorld.vue 4:14-375 13:3-17:5 14:22-383
 @ ./src/components/HelloWorld.vue
 @ ./src/router/index.js
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

那是sass-loader 版本太高, 更换成 7.3.1

 npm uninstall sass-loader(卸载当前版本)
 npm install sass-loader@7.3.1 --save-dev

在build文件夹下的webpack.base.conf.js的rules里面添加配置

{
    test: /\.scss$/,
    loaders: ['style', 'css', 'sass']
}

就可以在别的文件中引

引入scss文件,使用

@import '../assets/scss/triangle.scss'

不用使用

@import url('../assets/scss/triangle.scss');

会产生报错

第二种:Syntax Error: Error: PostCSS received undefined instead of CSS string

 ERROR  Failed to compile with 1 error7:07:54 ├F10: PM┤
 
 error  in ./src/components/TotalSales/index.vue?vue&type=style&index=0&id=86e7da4a&lang=scss&scoped=true&
 
Syntax Error: Error: PostCSS received undefined instead of CSS string
 
 @ ./node_modules/vue-style-loader??ref--8-oneOf-1-0!./node_modules/css-loader/dist/cjs.js??ref--8-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/src??ref--8-oneOf-1-2!./node_modules/sass-loader/dist/cjs.js??ref--8-oneOf-1-3!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/TotalSales/index.vue?vue&type=style&index=0&id=86e7da4a&lang=scss&scoped=true& 4:14-478 14:3-18:5 15:22-486

问题原因

node-sass 和 sass-loader 版本与当前的不兼容,安装对应版本的包即可。

解决方案

卸载node-sass 和 sass-loader

npm uninstall node-sass sass-loader

安装对应版本的包

npm install node-sass@4.14.1 sass-loader@8.0.0 --dev

第三种:Cannot find module ‘node-sass’

按照往常的思路,应该是 npm install 的时候,出错了。于是我选择重新 npm install node-sass -D,但是安装的时候,报错了

gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli   'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli   'D:\\vue\\readbook-admin\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli   'rebuild',
gyp verb cli   '--verbose',
gyp verb cli   '--libsass_ext=',
gyp verb cli   '--libsass_cflags=',
gyp verb cli   '--libsass_ldflags=',
gyp verb cli   '--libsass_library='
gyp verb cli ]
gyp info using node-gyp@3.8.0
gyp info using node@12.15.0 | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\vue\readbook-admin\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\vue\readbook-admin\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\vue\readbook-admin\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\vue\readbook-admin\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\vue\readbook-admin\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\vue\readbook-admin\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:158:21)
gyp verb `which` failed  python2 Error: not found: python2
gyp verb `which` failed     at getNotFoundError (D:\vue\readbook-admin\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (D:\vue\readbook-admin\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (D:\vue\readbook-admin\node_modules\which\which.js:80:29)
gyp verb `which` failed     at D:\vue\readbook-admin\node_modules\which\which.js:89:16
gyp verb `which` failed     at D:\vue\readbook-admin\node_modules\isexe\index.js:42:5
gyp verb `which` failed     at D:\vue\readbook-admin\node_modules\isexe\windows.js:36:5
gyp verb `which` failed     at FSReqCallback.oncomplete (fs.js:158:21) {
gyp verb `which` failed   stack: 'Error: not found: python2\n' +
gyp verb `which` failed     '    at getNotFoundError (D:\\vue\\readbook-admin\\node_modules\\which\\which.js:13:12)\n' +
gyp verb `which` failed     '    at F (D:\\vue\\readbook-admin\\node_modules\\which\\which.js:68:19)\n' +
gyp verb `which` failed     '    at E (D:\\vue\\readbook-admin\\node_modules\\which\\which.js:80:29)\n' +
gyp verb `which` failed     '    at D:\\vue\\readbook-admin\\node_modules\\which\\which.js:89:16\n' +
gyp verb `which` failed     '    at D:\\vue\\readbook-admin\\node_modules\\isexe\\index.js:42:5\n' +
gyp verb `which` failed     '    at D:\\vue\\readbook-admin\\node_modules\\isexe\\windows.js:36:5\n' +
gyp verb `which` failed     '    at FSReqCallback.oncomplete (fs.js:158:21)',
gyp verb `which` failed   code: 'ENOENT'
gyp verb `which` failed }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` succeeded python C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\DELL\AppData\Local\Programs\Python\Python37-32\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:295:12)
gyp ERR! stack     at ChildProcess.emit (events.js:223:5)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "D:\\vue\\readbook-admin\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\vue\readbook-admin\node_modules\node-sass
gyp ERR! node -v v12.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\watchpack\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
 
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!     C:\Users\DELL\AppData\Roaming\npm-cache\_logs\2020-05-12T01_07_50_553Z-debug.log

安装了 最新版本的 npm install node-sass@latest -D。

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

相关文章

  • vue3中markRaw示例详解

    vue3中markRaw示例详解

    markRaw是将一个对象标记为普通对象,而toRaw是将reactive对象变为普通对象,在 Vue 3 中,markRaw 是一个用于告诉 Vue 的响应性系统不要对某个对象进行转换或追踪其响应性的函数,下面给大家介绍vue3中markRaw详解,感兴趣的朋友一起看看吧
    2024-04-04
  • 在Vue项目中使用Typescript的实现

    在Vue项目中使用Typescript的实现

    这篇文章主要介绍了在Vue项目中使用Typescript的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-12-12
  • vue的生命周期钩子与父子组件的生命周期详解

    vue的生命周期钩子与父子组件的生命周期详解

    Vue的生命周期就是vue实例从创建到销毁的全过程,也就是new Vue() 开始就是vue生命周期的开始。Vue 实例有⼀个完整的⽣命周期,也就是从开始创建、初始化数据、编译模版、挂载Dom -> 渲染、更新 -> 渲染、卸载 等⼀系列过程,称这是Vue的⽣命周期
    2022-08-08
  • VUE实现分布式医疗挂号系统预约挂号首页步骤详情

    VUE实现分布式医疗挂号系统预约挂号首页步骤详情

    这篇文章主要为大家介绍了VUE实现分布式医疗挂号系统预约挂号首页步骤详情,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-04-04
  • 基于Vue3实现图片拖拽上传功能

    基于Vue3实现图片拖拽上传功能

    前端开发中,用户体验是至关重要的,图像上传是许多 web 应用中经常需要的功能之一,为了提升用户的交互体验,拖拽上传功能可以减少用户的操作步骤,本文将介绍如何使用 Vue 3实现一个简单的图片拖拽上传功能,需要的朋友可以参考下
    2024-08-08
  • Vue+Element UI实现复制当前行数据的功能

    Vue+Element UI实现复制当前行数据的功能

    这篇文章主要介绍了如何使用Vue + Element UI 实现在列表的操作栏新增一个复制按钮,复制当前行的数据可以打开新增弹窗后亦可以跳转到新增页面,感兴趣的小伙伴可以参考下
    2023-11-11
  • vue中checkbox如何修改为圆形样式

    vue中checkbox如何修改为圆形样式

    这篇文章主要介绍了vue中checkbox如何修改为圆形样式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-12-12
  • vue配置vue.config.js超详细教程

    vue配置vue.config.js超详细教程

    Vue的配置项'vue.config.js'是用来配置Vue项目的构建配置的,它是一个可选的配置文件,放置在项目的根目录下,这篇文章主要给大家介绍了关于vue配置vue.config.js的相关资料,需要的朋友可以参考下
    2024-01-01
  • sortable+element 实现表格行拖拽的方法示例

    sortable+element 实现表格行拖拽的方法示例

    这篇文章主要介绍了sortable+element 实现表格行拖拽的方法示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-06-06
  • vue+element加入签名效果(移动端可用)

    vue+element加入签名效果(移动端可用)

    这篇文章主要介绍了vue+element加入签名效果(移动端),本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-06-06

最新评论