Skip to content

Failing to import compat/* ESM files #1479

Closed

Description

@jnavb

Using webpack, I'm getting the following error:

isMatchWith.js:12 Uncaught ReferenceError: exports is not defined
    at eval (isMatchWith.js:12:23)
    at ../../node_modules/es-toolkit/dist/compat/predicate/isMatchWith.js

I'm suspecting it comes due this part in the package.json

    "./compat/*": {
      "default": {
        "types": "./compat/*.d.ts",
        "default": "./compat/*.js"
      }
    },

Would something like this fix the issue? I'm trying to understand why compat/* is the only one that has a different export pattern: default vs import + require.

    "./compat/*": {
      "import": {
        "types": "./compat/*.d.mts",
        "default": "./compat/*.mjs"
      },
      "require": {
        "types": "./compat/*.d.ts",
        "default": "./compat/*.js"
      }
    },

Thanks

Activity

  1. jnavb commented on Oct 18, 2025

    @jnavb
    Author

    Update: I can confirm that downgrading to 1.39.3 solves the issue. Looking at the package.json for 1.39.3 looks exactly what I suggested, could this be a regression?

  2. raon0211 commented on Oct 24, 2025

    @raon0211
    Collaborator

    I think this issue might be related to using an older webpack version or configuration. It's actually completely fine to import CommonJS files from ESM files in Node.js—that's why we only define CommonJS versions of compat/*. We're trying to keep our package size down, and having dual CommonJS/ESM files for everything would make the packages significantly larger.

  3. jnavb commented on Oct 24, 2025

    @jnavb
    Author

    Closing the issue because I couldn't reproduce it in a minimal project.

    For future visitors, the problem might be caused by the webpack configuration since the webpack version I'm using is the latest at this time 5.102.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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