webpack-contrib / mini-css-extract-plugin

Lightweight CSS extraction plugin
MIT License
4.66k stars 389 forks source link

fix: no template for dependency error #1058

Closed hax0r31337 closed 8 months ago

hax0r31337 commented 11 months ago

This PR contains a:

Motivation / Use-Case

An error would thrown when CSS module called in an EJS Template, like this.

  ERROR in ./src/pages/style.scss
  No template for dependency: CssDependency
  Error: No template for dependency: CssDependency
      at JavascriptGenerator.sourceDependency (/home/user/data/dev/bloghaze/node_modules/webpack/lib/javascript/JavascriptGenerator.js:188:10)
      at JavascriptGenerator.sourceModule (/home/user/data/dev/bloghaze/node_modules/webpack/lib/javascript/JavascriptGenerator.js:112:9)
      at JavascriptGenerator.generate (/home/user/data/dev/bloghaze/node_modules/webpack/lib/javascript/JavascriptGenerator.js:98:8)
      at NormalModule.codeGeneration (/home/user/data/dev/bloghaze/node_modules/webpack/lib/NormalModule.js:1208:22)
      at /home/user/data/dev/bloghaze/node_modules/webpack/lib/Compilation.js:3332:22
      at /home/user/data/dev/bloghaze/node_modules/webpack/lib/Cache.js:93:5
      at Hook.eval [as callAsync] (eval at create (/home/user/data/dev/bloghaze/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
      at Cache.get (/home/user/data/dev/bloghaze/node_modules/webpack/lib/Cache.js:75:18)
      at ItemCacheFacade.get (/home/user/data/dev/bloghaze/node_modules/webpack/lib/CacheFacade.js:115:15)
      at Compilation._codeGenerationModule (/home/user/data/dev/bloghaze/node_modules/webpack/lib/Compilation.js:3325:9)
   @ ./src/pages/ sync ^\.\/.*$ ./style.scss
   @ ./node_modules/html-webpack-plugin/lib/loader.js!./src/template.ejs 17:20-48

  Child HtmlWebpackCompiler compiled with 1 error

After hours of debugging, I found out that CssDependencyTemplate is not injected to dependencyTemplates which assigned to the Compilation object for generating the code.
I moved the injection hook from thisCompilation to compilation to apply the template to all Compilation objects.

Breaking Changes

Additional Info

linux-foundation-easycla[bot] commented 11 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

alexander-akait commented 8 months ago

Closing due to inactivity. Please test with latest version and feel free to reopen if still regressions. Thanks!