windicss / windicss-webpack-plugin

🍃 Windi CSS for webpack ⚡
https://windicss.org/integrations/webpack.html
79 stars 19 forks source link

Cannot read property 'afterCompile' of undefined #108

Closed chenxingyu350128 closed 2 years ago

chenxingyu350128 commented 2 years ago

Describe the bug I follow the tutorial "https://windicss.org/integrations/webpack.html" then when I run the "npm run dev"

"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",

terminal throw the error: TypeError: Cannot read property 'afterCompile' of undefined at WindiCSSWebpackPlugin.apply (F:\learn\windicss-tutorial\node_modules_windicss-webpack-plugin@1.6.4@windicss-webpack-plugin\dist\plugin.cjs:130:20) at Compiler.apply (F:\learn\windicss-tutorial\node_modules.pnpm\r2.cnpmjs.org+tapable@0.2.9\node_modules\tapable\lib\Tapable.js:375:16) at webpack (F:\learn\windicss-tutorial\node_modules.pnpm\r2.cnpmjs.org+webpack@3.12.0\node_modules\webpack\lib\webpack.js:33:19) at startDevServer (F:\learn\windicss-tutorial\node_modules.pnpm\r2.cnpmjs.org+webpack-dev-server@2.11.5_webpack@3.12.0\node_modules\webpack-dev-server\bin\webpack-dev-server.js:367:16) at processOptions (F:\learn\windicss-tutorial\node_modules.pnpm\r2.cnpmjs.org+webpack-dev-server@2.11.5_webpack@3.12.0\node_modules\webpack-dev-server\bin\webpack-dev-server.js:350:5) at processTicksAndRejections (internal/process/task_queues.js:95:5)

Additional context image

harlan-zw commented 2 years ago

Hey @chenxingyu350128

This plugin requires the use of the compiler hooks, I don't know too much about using the webpack-dev-server CLI but I feel like maybe it doesn't support these?

If you're able to provide a reproduction repo I can confirm that, but the resolution may just be it's not supported.

Could you try webpack serve instead?

await-ovo commented 2 years ago

@chenxingyu350128 I think maybe you need to upgrade your webpack version to v4 or higher. v3 after-compile hook is used differently, like the following:

compiler.plugin("after-compile", function(compilation, callback) {
  // Do something ...
});
harlan-zw commented 2 years ago

Closing this as the above seems to be the issue, please re-open if that's not the case.