修改css-loader加载的webpack配置时,运行报错:
Failed to compile.
./src/demo.styl (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-8-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--5-oneOf-8-3!./node_modules/stylus-loader/dist/cjs.js??ref--5-oneOf-8-4!./src/demo.styl)
TypeError: this.getOptions is not a function
原因:
可能是对应的配置(如:stylus-loader)版本过高,或者没有使用正确的webpack配置语法。
解决办法:
1、对应css-loader
版本降级,如:less
、stylus
等降到合适的版本。
2、修改webpack
改为正确的css-loader配置。
如:
{
test: stylRegex,
exclude: stylModuleRegex,
use: getStyleLoaders(
{
importLoaders: 4,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
},
},
'stylus-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: stylModuleRegex,
use: getStyleLoaders(
{
importLoaders: 4,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
},
},
'stylus-loader'
),
},
或
{
test: postcssRegex,
exclude: postcssModuleRegex,
use: postcssLoader,
sideEffects: true,
},
{
test: postcssModuleRegex,
use: postcssLoader,
},
暂无评论