Skip to content

css-loader produces invalid es5 code #1033

Closed
@timocov

Description

@timocov
  • Operating System: windows 10
  • Node Version: 12.4
  • NPM Version: 6.13.4
  • webpack Version: 4.41.5
  • css-loader Version: 3.4.0

Expected Behavior

No JS code produced.

Actual Behavior

css-loader produces

// Exports
module.exports = {
undefined
};

what is incorrect es5 code (also I don't think that having exported undefined key with undefined value is good here).

Code

I'll fill code later if it's really needed, but just looking into the code you're able to see difference between 3.3 and 3.4 versions.

Just look at https://github.com/webpack-contrib/css-loader/blob/v3.3.2/src/utils.js#L387-L389 and https://github.com/webpack-contrib/css-loader/blob/v3.4.0/src/utils.js#L417-L479. Previously (in 3.3.2) if exports length is 0 then it returns empty string. Now it doesn't check it and after if (exports.length > 0) { variable exportLocalsCode is undefined so that's why it produces incorrect output.

How Do We Reproduce?

I don't have working example right now, but it looks like that it fails if css module exports nothing (e.g. :global expression only).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions