Closed DylanVause closed 10 months ago
Hello @DylanVause
thanks for the issue report. I will research this problem later this week.
import '@mui/material/Stack'; // <= disable this line or
import './index.css'; // <= disable this line to build successfully
// ^^^ If both these lines are enabled it will fail to build, regardless of the content of index.css
This bug has been already fixed. In your repo is missing the index.css
. Just add the pages/index.css
file and the build will not fail.
I can reproduce the issue from the subj.
Sorry, I forgot to commit to the repo. That is old code, the issue still exists. I have committed the new code.
I cloned the plugin repo to see if I can debug it. Removing line 1004 of /src/Plugin/AssetCompiler.js
seems to fix the issue, but I'm not sure what the line is for. Are there issues with removing this line?
if (!Collection.importStyleRootIssuers.has(issuer)) continue; // I removed this line
It is very angry bug/feature in Webpack:
If the same c.css
file was imported in many js files: a.js
and b.js
,
then Webpack processes the CSS module only for 1st a.js
, others parents will be ignored,
then we lost the relation for other parents: a.js
-> c.css
(ok) but b.js
-> c.css
(lost).
This is a biggest problem in Webpack: it has no cache/data where is saved all
parents (incoming connections
) of a dependency. Therefore we need walk through each JS file to search in dependencies of the parent, that is very dirty but the single working solution :-/
The original mini-css-extract-plugin
plugin use a different way to find imported CSS, but it is much more complex and not faster.
@DylanVause Thank you for the fix in one line! All tests passed. The fix is in the version 3.4.7
.
The side-effect of the fix: increases build time for cases when many js files do not import css.
Thank you for the update. I can confirm 3.4.7
works on my end.
Current behaviour
I build a React component
Foo
withFoo.css
for styles. I useFoo
inPage A
andPage B
, which are two near-identical HTML pages powered by React. Oddly,Foo
is only styled in eitherPage A
orPage B
, but not both. Note that the same issue apples to componentBar
.Foo.tsx
:Foo.css
:pageA.html
:pageB.html
:pageA.tsx
(pageB.tsx
is similar):For some reason, in the output directory, only one of
pageA.{contenthash}.css
orpageB.{contenthash}.css
is generated, but not both. Expected behaviour is that both would be generated.The generated HTML files look like this:
pageA.html (generated)
:pageB.html (generated)
:Expected behaviour
Foo
should be styled in bothPage A
andPage B
. BothpageA.{contenthash}.css
andpageB.{contenthash}.css
should be generated and included inpageA.html
andpageB.html
.Reproduction Example
I have a mini reproduction example here: https://github.com/DylanVause/webpack-multiple-css-imports-bug
Environment
Additional context
My Webpack config is in the reproduction repository, but I will include it here as well for convenience:
Thank you for investigating this issue. I apologize in advance if this 'bug' is an error on my part.