解决less-loader 报错 TypeError: this.getOptions is not a function
问题
less-loader 报错 TypeError: this.getOptions is not a function at Object.lessLoader :
Failed to compile.
./src/views/Login.vuevuetype=styleindex=0id=26084dc2lang=lessscoped=true (./node_modules/css-loader/dist/cjs.jsref--10-oneOf-1-1!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/postcss-loader/srcref--10-oneOf-1-2!./node_modules/less-loader/dist/cjs.jsref--10-oneOf-1-3!./node_modules/cache-loader/dist/cjs.jsref--0-0!./node_modules/vue-loader/libvue-loader-options!./src/views/Login.vuevuetype=styleindex=0id=26084dc2lang=lessscoped=true)
Module build failed (from ./node_modules/less-loader/dist/cjs.js):
TypeError: this.getOptions is not a function
at Object.lessLoader (F:\VS Code\Vue\supply\node_modules\less-loader\dist\index.js:21:24)
原因
因为less-loader
版本太高问题,webpack和less-loader版本兼容问题导致的,需要降低版本。
解决
1.先卸载掉原先的版本
2.通过命令行的方式安装指定的版本(注意:在你当前项目里安装即可,不用全局安装,所以加-D即可)
npm uninstall less-loader
# npm install less@3.9.0 less-loader@5.0.0 -s
npm install less-loader@5.0.0