minimatch: `10.0.2` release is a breaking change (`ERR_REQUIRE_ESM`) published as a patch

Recent release (tag: 10.0.2) bumps dependency brace-expansion to ^4.0.0 from ^2.0.0. However, the release 3.0.0 converts the package to ESM, which is effectively a breaking change for any consumer in the dependency chain.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 59
  • Comments: 23 (2 by maintainers)

Commits related to this issue

Most upvoted comments

As a workaround, this can be solved using the overrides field of package.json. For example if you are importing this package through glob:

{
  "name": "myproject",
  "version": "0.0.0",
  "devDependencies": {
    "glob": "^11.0.0",
    // ...
  },
  "overrides": {
    "glob": {
      "minimatch": "10.0.1"
    }
  }
}

cdk-assets depends on this package as well, seeing similar error to above.

FYI - the vulnerability in brace-expansion that was the driver for bumping from ^2.0.0 to ^4.0.0 has now also been patched in 2.0.2, so going back to v 10.0.1 should be free from the vulnerability and avoid the cjs migration (provided you clear package-lock.json / yarn.lock / etc.)

it also broke my sanity project, here’s a solution that works. the previous solutions in this discussion did not work, i had to supplement them and now everything is successful.

  "overrides": {
    "minimatch": "10.0.1",
    "brace-expansion": "^2.0.1",
    "glob": {
      "minimatch": "10.0.1",
      "brace-expansion": "^2.0.1"
    }
  },
  "resolutions": {
    "minimatch": "10.0.1",
    "brace-expansion": "^2.0.1"
  }

fixing commit — https://github.com/mbozhik/arka/commit/a3639fefe1eddfeed8f7be55d28f39477d7a095f

Fix on my side (for now) is to force all packages to use 10.0.1 instead using:

    "overrides": {
        "minimatch": "10.0.1"
    }

The actual problem appears to be the fact brace-extensions jumped 2 major versions. (2.x to 4.x) somewhere in the chain of dependencies.

EDIT: Missed that someone already shared this.

This was all mentioned in the original vulnerability issue as well https://github.com/isaacs/minimatch/issues/254

In my case, I am depending on this package via ts-config-schema-generator:

└─┬ ts-json-schema-generator@2.4.0
  └─┬ glob@11.0.1
    └── minimatch@10.0.2

Example of the kind of errors that can be seen due to import with a CJS style module-resolution

/root/.npm/_npx/dec19a6f9609cbed/node_modules/minimatch/dist/commonjs/index.js:7
const brace_expansion_1 = __importDefault(require("brace-expansion"));
                                      ^
Error [ERR_REQUIRE_ESM]: require() of ES Module /root/.npm/_npx/dec19a6f9609cbed/node_modules/brace-expansion/index.js from /root/.npm/_npx/dec19a6f9609cbed/node_modules/minimatch/dist/commonjs/index.js not supported.
Instead change the require of /root/.npm/_npx/dec19a6f9609cbed/node_modules/brace-expansion/index.js in /root/.npm/_npx/dec19a6f9609cbed/node_modules/minimatch/dist/commonjs/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/root/.npm/_npx/dec19a6f9609cbed/node_modules/minimatch/dist/commonjs/index.js:7:43)
    at Object.<anonymous> (/root/.npm/_npx/dec19a6f9609cbed/node_modules/glob/dist/commonjs/index.js:9:21)
    at Object.<anonymous> (/root/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/factory/program.js:9:16)
    at Object.<anonymous> (/root/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/factory/generator.js:8:22)
    at Object.<anonymous> (/root/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/ts-json-schema-generator.js:9:24)
    at Object.<anonymous> (/root/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/bin/ts-json-schema-generator.js:4:1) {
  code: 'ERR_REQUIRE_ESM'
}