Skip to content

Error with [contenthash] not being implemented when the CSS experiment is enabled #18511

@titouanmathis

Description

@titouanmathis

Bug report

What is the current behavior?

When enabling the CSS experiment and using the [contenthash] placeholder in output.chunkFilename and with async import in JavaScript files, the following error is thrown on build:

ERROR in Path variable [contenthash] not implemented in this context: [name].[contenthash].css

If the current behavior is a bug, please provide the steps to reproduce.

See https://github.com/titouanmathis/repro-webpack-contenthash-error

What is the expected behavior?

The build should not throw an error, and we should be able to use the [contenthash] placeholder for chunks' filename.

Other relevant information:
webpack version: 5.92.0
Node.js version: 20
Operating System: macOS
Additional tools: not relevant

Fix

I was able to identify the commit (c561748) introducing the bug with git bisect. The bug seems to occur when modules is undefined in lib/css/CssModulesPlugin.js:363. Wrapping the following lines in the condition below fixes the error.

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