首页 > 解决方案 > 为什么 less-loader 不起作用 TypeError: this.getOptions is not a function

问题描述

我有一个 react+typescript 项目。我遇到了这个问题,less-loader 不能工作。我在 stackoverflow 中找到了答案,安装 less-loader@5.0.0 但它不起作用。

这是我的配置 webpack

  {
              test: lessRegex,
              exclude: lessModuleRegex,
              use: getStyleLoaders(
                  {
                    importLoaders: 2,
                    sourceMap: isEnvProduction && shouldUseSourceMap,
                  },
                  'less-loader'
              ),
              // Don't consider CSS imports dead code even if the
              // containing package claims to have no side effects.
              // Remove this when webpack adds a warning or an error for this.
              // See https://github.com/webpack/webpack/issues/6571
              sideEffects: true,
            },
// Adds support for CSS Modules, but using SASS
// using the extension .module.scss or .module.sass
            {
              test: lessModuleRegex,
              use: getStyleLoaders(
                  {
                    importLoaders: 2,
                    sourceMap: isEnvProduction && shouldUseSourceMap,
                    modules: true,
                    getLocalIdent: getCSSModuleLocalIdent,
                  },
                  'less-loader'
              ),
            },

包.json

   "webpack": "4.44.2",
    "less": "^4.1.2",
    "less-loader": "^5.0.0",

有人可以帮我吗?请。

标签: webpackless

解决方案


推荐阅读