Skip to content
Latchkey

ESLint "Must use import to load ES Module" (flat config) in CI

ESLint tried to load a config or plugin with require(), but the target is an ES module. This often hits eslint.config.js flat config in a project that is not marked as ESM.

What this error means

ESLint exits with "Error: Must use import to load ES Module: /app/eslint.config.js" or a similar message naming a plugin file.

node
Error: Must use import to load ES Module: /app/eslint.config.js
require() of ES Module /app/eslint.config.js from /app/node_modules/eslint/... not supported.

Common causes

Flat config written as ESM in a CJS package

eslint.config.js uses export default but the package is not "type": "module", so loading it via require() fails.

A plugin or shareable config that is ESM-only

An imported plugin ships only as ESM and the config tried to require it.

How to fix it

Mark the package as ESM or rename the config

Either set "type": "module", or rename the flat config to eslint.config.mjs so it is always loaded as ESM.

Terminal
mv eslint.config.js eslint.config.mjs

Use CommonJS config syntax if the package is CJS

If you keep CommonJS, write the flat config with module.exports in a .cjs file.

eslint.config.cjs
// eslint.config.cjs
module.exports = [
  { rules: { 'no-unused-vars': 'error' } }
];

How to prevent it

  • Match the config file format to the package type field.
  • Use .mjs/.cjs for ESLint config to remove ambiguity.
  • Check whether plugins are ESM-only before requiring them.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →