Node.js

ERR_REQUIRE_ESM: require() of ES Module not supported

ERR_REQUIRE_ESM

You used require() to load a package that is ESM-only (has "type": "module" or .mjs).

Common Causes

Fixes

  1. 1. Use dynamic import
    const mod = await import('esm-only-package');
  2. 2. Convert project to ESM
    "type": "module" in package.json
  3. 3. Use createRequire
    import { createRequire } from 'module';
    const require = createRequire(import.meta.url);

Still not fixed?

Related Errors

DuskTools That Might Help

All Errors