Skip to content

CommonJS plugin doesn't recognize the __esModule field in module.exports = { __esModule: true, ... } #939

@haoqunjiang

Description

@haoqunjiang

Expected Behavior

Both imports from symbol and symbol2 return the .default field because they are both compiled from an ES module and contain the __esModule field.

Actual Behavior

The CommonJS plugin only recognizes the one with exports.__esModule. The one with module.exports = { __esModule: true, default: ... } is treated as a normal CJS module.

Additional Information

The module.exports = { __esModule: true, default: ... } pattern is found in babel-runtime v6 https://unpkg.com/browse/[email protected]/core-js/symbol.js

It is used in some old codebases. So this issue causes incompatibility with them.

See also vitejs/vite#4090

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