Skip to content

module-interop/no-import-cjs ​

disallow importing CommonJS modules

📖 Rule Details ​

This rule reports ES module imports of CommonJS modules.

Although it is possible to ESM import CommonJS modules due to module interoperability across bundlers and runtimes, their behavior may not be consistent.
To avoid issues due to these differences, it is safe to ESM import only ESMs.

js
/* eslint module-interop/no-import-cjs: 'error' */

/* ✓ GOOD */
import x from './my-module.mjs';

/* ✗ BAD */
import y from 
'./my-module.cjs'
;

🔧 Options ​

Nothing.

🚀 Version ​

This rule was introduced in eslint-plugin-module-interop v0.1.0

🔍 Implementation ​