Vue项目 Module build failed: TypeError: this.getResolve is not a function at Object.loader……

由于还用不惯 webpack 4,特别是采用了vue-cli3 搭建的项目,由于还没搞懂在这种环境中自己手动调整配置(vue-cli3 简化了配置,原来很多的配置都集成到vue-cli3内部,不需要在通过显性的配置了,至少目前觉得反而不方便了),所以又换回了webpack 3.6,还是采用vue-cli2(vue init webpack projectName 搭建环境)。
当采用scss来实现样式时,需要安装sass-loader和node-sass,才能正常加载解析scss文件。
然而问题就这么来了,编译报错,前前后后检查了很多遍,明明已经安装了sass-loader啦,报错还是提示loader异常,以下是完整的报错:

 ERROR  Failed to compile with 1 errors                                                                                                                                                                                  11:04:57 PM
     error  in ./src/views/module/customer/topology/topologyList.vue
    
    Module build failed: TypeError: this.getResolve is not a function
        at Object.loader (E:\appEx\PreResearch\orchestrator\topology\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-0b9912b5","scoped":false,"hasInlineConfig":false}!./node_modules/sass-loader/dist/cjs.js?{"sourceMap":true}!./node_modules/vue-loader/lib/selector.js?type=styles&index=0!./src/views/module/customer/topology/topologyList.vue 4:14-414 13:3-17:5 14:22-422

 

从报错来看,应该还是loader的问题,然后就删除重装sass-loader,node-sass,来来回回不下5次,还是报同样的错误,甚至怀疑是不是webpack.dev.config.js中没有配置好?一步步检查,也没有发现问题。
最后换git bash 来重新执行了一边npm install 代码,这个时候发现了问题…… ,由于之前我都是直接在vsCode中直接新建终端来执行shell脚本的,界面比较小,所以没有显示完整的日志,这次终于发现了蹊跷。

npm WARN [email protected] requires a peer of webpack@^4.36.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of sass@^1.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of fibers@>= 3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

 

我安装的sass-loader由于没有限定版本,安装的是最新的8.0.0版本,该版本是支持webpack4.36.0的,导致不匹配,最后再次删除安装的sass-loader,并重新指定7.0.3版本的sass-loader,终于不报错了。

指定特定版本
npm install [email protected] --save-dev

这里还有一个版本号的问题,如果想指定明确的版本号,那么直接写死对应的,即@7.0.3 那么安装的就是7.0.3的,如果不确定版本号,又能接受微调的,那么可以采用 “~” 即 ~7.0.3 来表示,允许第二位进行更新优化,即 接受 7.0.0 ~ 7.1.0 即只要第一位不变,第二位允许加1,其他的选取最新的版本编号。^7.0.3 则表示允许第一位加1,即在7.0.3 ~ 8.0.0 之间的版本(不包括8.0.0),如果直接用 * 号代替,则表示不限制,如果想要获取最新版本,则可以直接加上latest。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章