Coding⏱️ 2 min read📅 2026-06-03

How to Fix: ESLint - Error: Must use import to load ES Module

ESLint error when using ES Module with import statement.

Quick Answer: The issue is likely due to the fact that you are trying to use an ES module (`.mjs` file) without importing it correctly. Try adding the `type: 'module'` option in your `webpack.config.js` file or changing the file extension to `.js`.

The error 'Must use import to load ES Module' typically occurs when you're trying to run ESLint with a file that uses the CommonJS module syntax in an ES module environment.

🛑 Root Causes of the Error

  • Using CommonJS imports with ES modules.

✅ Best Solutions to Fix It

Method 1: Using ES Imports

  1. Step 1: Replace all CommonJS imports with ES imports, e.g., `require('module')` becomes `import { module } from 'module';

Method 2: Using Babel

  1. Step 1: Install the necessary configuration for Babel to work with ESLint, e.g., `babel-preset-env` and `@babel/plugin-transform-modules-commonjs`.

✨ Wrapping Up

By following these methods, you should be able to resolve the 'Must use import to load ES Module' error and ensure a smooth ESLint experience.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions