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

[2.0.0] URL used multiple times across imported files produces "undefined" rather than expected URL. #864

Closed
Lattyware opened this issue Dec 9, 2018 · 3 comments

Comments

@Lattyware
Copy link

Lattyware commented Dec 9, 2018

After upgrading to 2.0.0 from 1.0.1, I am getting url(undefined) in my output CSS where I previously got a valid URL.

This seems to happen when the URL is referenced multiple times across imported files - after the first reference undefined is output.

  • Operating System: Arch Linux
  • Node Version: 11.3.0
  • NPM Version: 6.4.1
  • webpack Version: 4.27.1
  • css-loader Version: 2.0.0

Expected Behavior

The URL should be the same each time it is referenced.

Actual Behavior

undefined is output instead of the URL after the first reference.

Code

@import "./test2";

.test1 {
    background: url(../../assets/test.png);
}
.test2 {
    background: url(../../assets/test.png) repeat;
}

Produces:

With css-loader@2.0.0:

.test2{background:url(d41d8cd98f00b204e9800998ecf8427e.png) repeat}.test1{background:url(undefined)}

With css-loader@1.0.1:

.test2{background:url(d41d8cd98f00b204e9800998ecf8427e.png) repeat}.test1{background:url(d41d8cd98f00b204e9800998ecf8427e.png)}

How Do We Reproduce?

See the attached project, which works with css-loader@1.0.1 but fails with css-loader@2.0.0.

@Lattyware Lattyware changed the title undefined URL. URL used multiple times results in getting "undefined" in output. Dec 9, 2018
@Lattyware Lattyware changed the title URL used multiple times results in getting "undefined" in output. URL used multiple times results in getting "undefined" in output as of v2.0.0. Dec 9, 2018
@Lattyware Lattyware changed the title URL used multiple times results in getting "undefined" in output as of v2.0.0. [2.0.0] URL used multiple times across imported files produces "undefined". Dec 9, 2018
@Lattyware Lattyware changed the title [2.0.0] URL used multiple times across imported files produces "undefined". [2.0.0] URL used multiple times across imported files produces "undefined" rather than expected URL. Dec 9, 2018
@alexander-akait
Copy link
Member

@Lattyware thanks for issue, it is bug 👍

@alexander-akait
Copy link
Member

Sorry not related to css-loader, problem in extract-loader, problem here https://github.com/peerigon/extract-loader/blob/master/src/extractLoader.js#L144, need rewrite logic, maybe use Object/Map (like { __EXTRACT_LOADER_PLACEHOLDER__000_000: 'asset.png' }) and get asset url based __EXTRACT_LOADER_PLACEHOLDER__000_000 index.

My recommendation is to switch on https://github.com/webpack-contrib/mini-css-extract-plugin

@james-camilleri
Copy link

I've also encountered this issue. I can see what you mean regarding the issues in extract-loader's code, but why did this only surface with css-loader 2.0.0+? Reverting to an earlier version of the css-loader plugin solves this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants