Skip to content

Bug in Webpack 3 and 4: can't require a module with a ESM entry point #6584

@TehShrike

Description

@TehShrike

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?

If you require a package with a module field in its package.json, and the module has an export default, the require call does not return the default export like it should.

Instead, it returns an object with default and all properties.

Both of these forms will return the default export:

const merge = require('deepmerge').default
import merge from 'deepmerge'

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

Reproduction at https://github.com/perry-mitchell/repo-deepmerge-webpack

What is the expected behavior?

require('any-esm-module') should return the default export.

For many Webpack users, require('any-esm-module').default is not even an option, since they are importing a package that depends on some CJS/ESM module (like deepmerge).

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Tested with Webpack 3.11.0 and 4.0.0.


Edit: per the discussion below, my original report above is incorrect.

What should probably happen: require('my-module') should import the main (or browser) entry point in the package.json file.

What happens now: require('my-module') imports the module entry point in the package.json file.

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