Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with the latest version of mini-css-extract-plugin (0.4.3) #167

Closed
Lyrkan opened this issue Oct 7, 2018 · 14 comments
Closed

Comments

@Lyrkan
Copy link

Lyrkan commented Oct 7, 2018

Hi there,

It seems that there is an issue when using the latest versions of the mini-css-extract-plugin and this plugin together.

We have a test case in Webpack Encore with the following stylesheet:

// roboto_font.css
@font-face {
    font-family: 'Roboto';
    src: url('./../fonts/Roboto.woff2') format('woff2');
}

When we require that file with mini-css-extract-plugin@0.4.2 everything works as intended, however with mini-css-extract-plugin@0.4.3 we get the following manifest (don't mind the other entries):

{
	"build/bg.css": "/build/bg.css",
	"build/font.css": "/build/font.css",
	"build/main.js": "/build/main.js",
	"build/runtime.js": "/build/runtime.js",
	"build/images/another_bg_image.css": "/build/images/symfony_logo.ea1ca6f7.png",
	"build/fonts/roboto_font.css": "/build/fonts/Roboto.9896f773.woff2"
}

As you can see, instead of having a "build/fonts/Roboto.woff2" key, we get "build/fonts/roboto_font.css"... which doesn't feel right at all :)

I tracked down the issue to this PR: webpack-contrib/mini-css-extract-plugin#177 (comment)

Apparently webpack-assets-manifest was also affected and managed to solve it (webdeveric/webpack-assets-manifest#39).

@karlvr
Copy link

karlvr commented Nov 13, 2018

I've just come across this issue. It appears to be caused because the mini-css-extract-plugin (I didn't establish it conclusively as the source, but it seems like it) is causing our moduleAsset function to be called a second time for a given static asset (e.g. background.png) but with module.userRequest set to the CSS source file. So we end up mapping background.png to main.css and then in our manifest end up with "main.css": "background.HASH.png" in our manifest. Of course because we can only have one key for "main.css", but there are likely multiple assets referenced by it, we also lose any mention of lots of our assets.

The solution in
webdeveric/webpack-assets-manifest#39 looks like it might actually be just because they check that they haven't already got a mapping for the file before adding it.

A similar, but simpler change works here if we add to the moduleAsset function a check that moduleAssets[file] is not already set. Is it safe to assume that the first time we hear about an asset, it's always the asset itself, and that the CSS referencing the asset will always follow...?

karlvr added a commit to karlvr/webpack-manifest-plugin that referenced this issue Nov 13, 2018
Resolves shellscape#167

mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177
karlvr added a commit to karlvr/webpack-manifest-plugin that referenced this issue Nov 13, 2018
Second attempt. Based on webdeveric/webpack-assets-manifest#40

Resolves shellscape#167

mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177
mwistrand added a commit to mwistrand/cli-build-app that referenced this issue Nov 20, 2018
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2
  until shellscape/webpack-manifest-plugin#167
  is resolved
- Remove the style loader as it is no longer needed
- Replace removed CommonsChunkPlugin with `optimize.splitChunks`
  configuration option
- Remove plugins provided by `mode` configuration option:
  NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
mwistrand added a commit to mwistrand/cli-build-app that referenced this issue Nov 20, 2018
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2
  until shellscape/webpack-manifest-plugin#167
  is resolved
- Remove the style loader as it is no longer needed
- Replace removed CommonsChunkPlugin with `optimize.splitChunks`
  configuration option
- Remove plugins provided by `mode` configuration option:
  NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
mwistrand added a commit to mwistrand/cli-build-app that referenced this issue Nov 22, 2018
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2
  until shellscape/webpack-manifest-plugin#167
  is resolved
- Remove the style loader as it is no longer needed
- Replace removed CommonsChunkPlugin with `optimize.splitChunks`
  configuration option
- Remove plugins provided by `mode` configuration option:
  NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
mwistrand added a commit to mwistrand/cli-build-app that referenced this issue Nov 29, 2018
- Temporarily add local, upgraded `@dojo/webpack-contrib`
- Temporarily update package.json for CI
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2
  until shellscape/webpack-manifest-plugin#167
  is resolved
- Replace removed CommonsChunkPlugin with `optimize.splitChunks`
  configuration option
- Remove plugins provided by `mode` configuration option:
  NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
- Use terser-webpack-plugin over uglifyjs-webpack-plugin-terser
- Upgrade to webpack-mild-compile@3.3.1
- Add runtime chunk, disable default chunk, and force modules into main
  chunk
- Filter css order warnings
- Move optimize-css-assets-webpack-plugin to dist config
- Update tapable typings
mwistrand added a commit to dojo/cli-build-app that referenced this issue Nov 30, 2018
- Update webpack-contrib to next
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2
  until shellscape/webpack-manifest-plugin#167
  is resolved
- Replace removed CommonsChunkPlugin with `optimize.splitChunks`
  configuration option
- Remove plugins provided by `mode` configuration option:
  NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
- Use terser-webpack-plugin over uglifyjs-webpack-plugin-terser
- Upgrade to webpack-mild-compile@3.3.1
- Add runtime chunk, disable default chunk, and force modules into main
  chunk
- Filter css order warnings
- Move optimize-css-assets-webpack-plugin to dist config
- Update tapable typings
mwistrand added a commit to mwistrand/cli-build-widget that referenced this issue Dec 5, 2018
- Update webpack-contrib to next
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2
  until shellscape/webpack-manifest-plugin#167 is resolved.
- Replace removed CommonsChunkPlugin with `optimize.splitChunks`
  configuration option
- Remove plugins provided by `mode` configuration option:
  NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
- Use terser-webpack-plugin over uglifyjs-webpack-plugin-terser
- Upgrade to webpack-mild-compile@3.3.1
- Force CSS splitting by entry
- Filter css order warnings
- Add optimize-css-assets-webpack-plugin to dist config
- Update tapable typings
@fernandopasik
Copy link

The current workaround for this is to force the dependency to 0.4.2 through yarn resolutions.

mwistrand added a commit to dojo/cli-build-widget that referenced this issue Dec 16, 2018
- Update webpack-contrib to next
- Replace ExtractTextPlugin with MiniCssExtractPlugin, but pin to 0.4.2 until shellscape/webpack-manifest-plugin#167 is resolved.
- Replace removed CommonsChunkPlugin with `optimize.splitChunks` configuration option
- Remove plugins provided by `mode` configuration option: NamedChunksPlugin, NamedModulesPlugin, and DefinePlugin
- Use terser-webpack-plugin over uglifyjs-webpack-plugin-terser
- Upgrade to webpack-mild-compile@3.3.1
- Force CSS splitting by entry
- Filter css order warnings
- Add optimize-css-assets-webpack-plugin to dist config
- Update tapable typings
@electrocnic
Copy link

The current workaround for this is to force the dependency to 0.4.2 through yarn resolutions.

This did not help in my case :(
Using "mini-css-extract-plugin": "^0.5.0",

@a573367014
Copy link

目前的解决方法是通过纱线分辨率强制依赖性为0.4.2。

这对我的情况没有帮助:(
使用“mini-css-extract-plugin”:“^ 0.5.0”,

me too

@fernandopasik
Copy link

I mean in package.json have a resolutions key (this only works with yarn, not supported by npm)

{
  "devDependencies": {
    "mini-css-extract-plugin": "^0.4.2"
  },
  "resolutions": {
     "mini-css-extract-plugin": "0.4.2"
  }
}

for npm I guess you can force the version and that's it

{
  "devDependencies": {
    "mini-css-extract-plugin": "0.4.2"
  }
}

@harryfinn
Copy link

Thanks @fernandopasik, reverting to 0.4.2 fixed an issue in my webpack build whereby in development mode, font assets were removed after first rebuild and not being saved in the manifest correctly!

@hershmire
Copy link

Are there any plans for webpack-manifest-plugin to have a permanent fix?

@mauricesnip
Copy link

I'm having this issue with 2.0.4 in combination with mini-css-extract-plugin 0.7.0 and 0.8.0. Indeed, reverting to mini-css-extract-plugin@0.4.2 fixes this. Did anyone manage to get this to work with the recent versions of mini-css-extract-plugin?

@TheDutchCoder
Copy link

I can confirm this issue.

it also happens with PostCSS and ExtractCssPlugin, where (for example) fonts end up as a single entry like this:

"fonts/app.pcss": "/static/redesign/fonts/Nimbus-Sans-Novus-Semibold.woff",

Both the key and value make no sense.

mastilver pushed a commit that referenced this issue Sep 25, 2019
mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177

fixes #167
@mastilver mastilver mentioned this issue Sep 25, 2019
5 tasks
mastilver pushed a commit that referenced this issue Sep 25, 2019
mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177

fixes #167
mastilver pushed a commit that referenced this issue Sep 25, 2019
mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177

fixes #167
mastilver pushed a commit that referenced this issue Sep 25, 2019
mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177

fixes #167
@mastilver mastilver mentioned this issue Sep 25, 2019
Closed
mastilver pushed a commit that referenced this issue Sep 26, 2019
mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177

fixes #167
@mastilver
Copy link
Contributor

#176 is available on 3.0.0-rc.0

@pascalw
Copy link

pascalw commented Dec 4, 2019

I was running into this issue and can confirm that 3.0.0-rc.0 solves it.

pascalw added a commit to kabisa/specimen-skeleton that referenced this issue Dec 4, 2019
pascalw added a commit to pascalw/11ty-boilerplate that referenced this issue Dec 4, 2019
karlvr added a commit to karlvr/webpack-manifest-plugin that referenced this issue Jan 29, 2020
Resolves shellscape#167

mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177
karlvr added a commit to karlvr/webpack-manifest-plugin that referenced this issue Jan 29, 2020
Second attempt. Based on webdeveric/webpack-assets-manifest#40

Resolves shellscape#167

mini-css-extract-plugin reports additional, incorrect information for files that are refenced in CSS. The first time we see the file the `module.userRequest` is correct, and we add to `moduleAssets` correctly. However mini-css-extract-plugin then also reports the same `file` but with `module.userRequest` set to the CSS file that references it, which caused us to overwrite the good value in `moduleAssets`.

See the change in mini-css-extract-plugin that caused this webpack-contrib/mini-css-extract-plugin#177
@stale stale bot added the x⁷ ⋅ stale label Oct 25, 2020
@alex996
Copy link

alex996 commented Nov 19, 2020

Unfortunately, the issue still occurs with the current mini-css-extract-plugin (v1.3.1). I've put up a minimal repro in this repository, but in short, the plugin emits incorrect keys for CSS files, for example:

{
  "main.css": "style.b248c6e8f370b3bc8646.css", // <--- key should be "style.css"
  "main.js": "main.3cf1156c43d58afb8952.js"
}

@shellscape Thanks in advance to your attention; I can create a separate issue if need be.

@shellscape
Copy link
Owner

@alex996 This is a webpack v5 issue. See #222

@shellscape
Copy link
Owner

v3.0.0 is published and should resolve this issue.

weaverryan added a commit to symfony/webpack-encore that referenced this issue Dec 31, 2020
This PR was squashed before being merged into the main branch.

Discussion
----------

Update Webpack to v5 (+ other dependencies)

Last week Webpack added a compat layer to its v5 alpha that allows the `mini-css-extract-plugin` to run on it (with deprecated messages). Since we include that plugin by default (and a lot of our tests relie on it) it was the main thing blocking us from preparing the migration.

---

I basically started from #564 which was updating some dependencies, enabling CSS HMR when needed and adding a `configureMiniCssExtractPlugin(...)` method, but with a few changes:
* no more inconsistent hashes checks for the `enableVersioning applies to js, css & manifest` test: it seems to be working fine by default
* no more embedding the `webpack-manifest-plugin` into our code: shellscape/webpack-manifest-plugin#167 is still an issue but @mastilver has been working on the project lately (which is why the plugin works with Webpack 5) and a fix has already been merged on the `next` branch, so it's probably only a matter of time now :). **Edit: Fixed in `webpack-manifest-plugin@^3.0.0-rc`**
* removal of Node 8 compatibility

So now, about the state of that PR:

**0 failing test left**:
* ~6 tests that will probably be fixed by webpack/webpack#10661 in `webpack@5.0.0-beta.15`: `Uncaught Error: Error when running the browser: Error: Error when running the browser: ReferenceError: mod is not defined`~
* ~All the 7 tests related to the `vue-loader` are failing with a `Cannot find module 'webpack/lib/RuleSet` error message (see: vuejs/vue-loader#1599
* ~1 test related to the `webpack-manifest-plugin` issue previously mentioned~
* ~1 test related to `createSharedEntry()` which doesn't seem to work properly~
* ~1 test related to Babel that doesn't transform an arrow function as expected~

**A lot of deprecation notices** (but most, if not all, of them are triggered by vendors), for instance:
* `Compilation.hooks.normalModuleLoader was moved to NormalModule.getCompilationHooks(compilation).loader`
* `Module.id: Use new ChunkGraph API`
* `Module.updateHash: Use new ChunkGraph API`
* `Chunk.modulesIterable: Use new ChunkGraph API`
* `ChunkGroup.getModuleIndex2 was renamed to getModulePostOrderIndex`
* `Compilation.chunks was changed from Array to Set (using Array method 'reduce' is deprecated)`
* `chunk.files was changed from Array to Set (using Array method 'reduce' is deprecated)`

**Some modules do not declare they are compatible with Webpack 5 yet** *(warning messages during `yarn install`)*: this shouldn't be an issue **unless** those modules require a major version upgrade to be officialy compatible (in which case breaking changes could impact us).

**We're still using `webpack-cli@3`** which may not support Webpack 5. It currently seems to be OK but we should probably upgrade to `webpack-cli@4` (currently in beta). I took a quick glance at it and it probably won't be an easy thing to do, mainly because of how our "runtime context" works and how the new version of the CLI calls Webpack (through another process).

Commits
-------

57f64fa Remove unusued files/constants related to versioning/shared entry
8d7843a Add removed Babel test back
216a5ca Update css-loader and style-loader
ddcd6d8 Merge branch 'main' into webpack5
444c37f Merge branch 'main' into webpack5
b292e76 Fix linting issues
d576b21 Remove deprecation caused by the DeletedUnusuedEntriesJSPlugin
b0f7190 Update some hashes in functional tests
4f6171b Update WebpackManifestPlugin to v3.0.0 and vue-loader to v16.1.0
9af90ee Remove wrong comment
50cea18 Bump min. Typescript version to 3.6.3
1d22520 Don't set hmr option for mini-css-extract-plugin (deprecated since 1.0.0)
564b147 Update Vue.js dependencies
8da531e Replace optimize-css-assets-webpack-plugin by css-minimizer-webpack-plugin
f3843ca Update Webpack to 5.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet