Skip to content

Unused default export causes ReferenceError when usedExports option is turned on #10542

@haoqunjiang

Description

@haoqunjiang

Bug report

What is the current behavior?

Under some circumstances, the tree shaking process for an unused default export would only remove the variable definition while still preserves the variable reference in an expression like var _unused_webpack_default_export = (style), causing a ReferenceError in browsers.

Since webpack 5.0.0-beta.14 turned optimization.usedExports on by default, this bug became quite noticeable.

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

git clone https://github.com/sodatea/webpack-used-exports-bug.git
cd webpack-used-exports-bug
yarn && yarn start

Then visit http://localhost:5000/example/index.html to see the error message.

What is the expected behavior?

Other relevant information:
webpack version: v5.0.0-beta.14
Node.js version: v12.16.1
Operating System: macOS Catalina 10.15.3
Additional tools: None

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