如何修复TypeError: stagedAutoprefixer is not a function错误?
修复 TypeError: stagedAutoprefixer is not a function 问题
这个错误是postcss-loader和autoprefixer版本不兼容导致的——SB Admin模板的默认PostCSS配置适配旧版依赖,新安装的高版本包会让stagedAutoprefixer调用失效,以下是几种修复方案:
方案1:降级依赖到兼容版本
卸载当前的postcss-loader和autoprefixer,安装适配模板的旧版本:
npm uninstall postcss-loader autoprefixer npm install postcss-loader@3.0.0 autoprefixer@9.8.6 --save-dev
方案2:更新PostCSS配置
如果不想降级,直接修改项目的PostCSS配置:
- 在项目根目录新建或修改
postcss.config.js,写入兼容新版的配置:
module.exports = { plugins: [ require('autoprefixer') ] }
- 打开
webpack.config.js,找到postcss相关配置,移除包含stagedAutoprefixer的代码块,比如这类过时配置要删掉:
postcss: function () { return { plugins: [require('autoprefixer')], stagedAutoprefixer: true }; }
方案3:清理缓存并重启
完成上述操作后,清理缓存重装依赖,再重启服务:
npm cache clean --force rm -rf node_modules package-lock.json npm install npm start
内容的提问来源于stack exchange,提问作者ThatGuynick
相关产品推荐
相关产品推荐

