为什么使用 mini-css-extract-plugin 构建资产在开发中有效但在 Heroku 构建过程中失败?

Why does asset building using mini-css-extract-plugin work in development but fail in Heroku build process?

尝试使用 node.js 和 ruby buildpack

部署到 Heroku

Git 推送到 Heroku 调用构建包和 rake asset:precompile 任务是 运行

不幸的是,此任务在“编译”阶段失败,每个 css/scss 要部署的资产文件都显示以下错误

ERROR in ./app/assets/stylesheets/base.css
Module build failed (from ./node_modules/@rails/webpacker/node_modules/mini-css-extract-plugin/dist/loader.js):
TypeError: Cannot read property 'tap' of undefined
at ExternalModuleFactoryPlugin.apply (/tmp/build_4b756368/node_modules/@rails/webpacker/node_modules/webpack/lib/ExternalModuleFactoryPlugin.js:17:37)
at /tmp/build_4b756368/node_modules/@rails/webpacker/node_modules/webpack/lib/ExternalsPlugin.js:16:63
at Hook.eval [as call] (eval at create (/tmp/build_4b756368/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
at Hook.CALL_DELEGATE [as _call] (/tmp/build_4b756368/node_modules/webpack/node_modules/tapable/lib/Hook.js:14:14)
at /tmp/build_4b756368/node_modules/webpack/lib/Compiler.js:1028:23
at Hook.eval [as callAsync] (eval at create (/tmp/build_4b756368/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/tmp/build_4b756368/node_modules/webpack/node_modules/tapable/lib/Hook.js:18:14)
at Compiler.compile (/tmp/build_4b756368/node_modules/webpack/lib/Compiler.js:1025:28)
at Compiler.runAsChild (/tmp/build_4b756368/node_modules/webpack/lib/Compiler.js:495:8)
at Object.pitch (/tmp/build_4b756368/node_modules/@rails/webpacker/node_modules/mini-css-extract-plugin/dist/loader.js:126:17)
@ ./app/javascript/packs/application.js 6:0-42

我遇到了完全相同的问题,我按照此处的说明升级到 Webpacker 的预发布版本:

https://github.com/rails/webpacker/blob/master/6_0_upgrade.md

这解决了我的问题,之后一切正常。