TypeError: this.getOptions is not a function 的解决(vue,react)

1.npm uninstall less-loader
2.npm install less-loader@5.0.0

一、报错信息 

TypeError: this.getOptions is not a function  这个是在运行项目是遇到的问题

                                                                          vue里 

                                                                       react里

这个报错是类型错误,this.getOptions 不是一个函数 。这个错误是less-loader库里的错误。

主要是less-loader版本太高,不兼容this.getOptions方法。

解决方案

1.问题的解决(方法一):通过 npm uninstall less-loader 命令卸载原版本的 less-loader,然后 通过 npm install less-loader@5.0.0 命令下载降级版本的 less-loader,这个问题就可以解决了.

1.npm uninstall less-loader
2.npm install less-loader@5.0.0

2.或者可以删除node_modules文件夹,并且把package.json里less-loader里的版本改为5.0.0就行,然后npm install

2021-12-16补充:

不止 less-loader 同样 scss-loader ,css-loader,style-loader都有可能出现 。

 只需要 看报错 具体 是什么 上图 为例 报的是css-loader .所以 卸载对应得就行。

1.npm uninstall css-loader
2.npm install css-loader@5.0.0

具体降到哪个版本 需要 看看 版本信息 比如 style-loader

style-loader - npmstyle loader module for webpack. Latest version: 3.3.1, last published: 5 months ago. Start using style-loader in your project by running `npm i style-loader`. There are 13931 other projects in the npm registry using style-loader.https://www.npmjs.com/package/style-loader降低 到 之前的版本 比如 2.0.0

还有可能出现 :

vue,react报错node sass version is incompatible with 4.0.0 ||5.0.0 解决方案https://blog.csdn.net/weixin_44058725/article/details/119238977?spm=1001.2014.3001.5502https://blog.csdn.net/weixin_44058725/article/details/119238977?spm=1001.2014.3001.5502

 2025/01/23 也可能出现这个错:

ValidationError: Invalid options object. CSS Loader has been initialized using an options object that does not match 
the API schema.
 - options has an unknown property 'localIdentName'. These properties are valid:
   object { url?, import?, modules?, sourceMap?, importLoaders?, localsConvention?, onlyLocals?, esModule? }

这个错误是因为你在配置 css-loader 时使用了 localIdentName 属性,但这个属性在 css-loader 的最新版本中已经被移除了。localIdentName 是用于配置 CSS Modules 的类名生成规则的,但在 css-loader 的较新版本中,这个配置被移到了 modules 属性下。

这个错误也可以降低 对应的库的版本 我的是css-loader

总结:

看问题报错,首先看是什么类型的错误,先确定是自己代码里的还是插件库里的报错。才能对症下药。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

崽崽的谷雨

漫漫前端路,摸爬滚打

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值