ESLint plugin that enforces imports to follow native ESM resolution
npm install eslint-plugin-import-esmESLint plugin that enforces imports to follow native ESM resolution.
You'll first need to install ESLint v9:
``sh`
npm i eslint --save-dev
Next, install eslint-plugin-import-esm:
`sh`
npm install eslint-plugin-import-esm --save-dev
This plugin works well with eslint-plugin-import, which validates existence of paths amongst other checks.
Using the recommended preset:
`js
import { defineConfig } from "eslint/config";
import importEsmPlugin from 'eslint-plugin-import-esm';
export default defineConfig([
importEsmPlugin.configs.recommended,
...
]);
`
Using without the recommended preset:
`js
import { defineConfig } from "eslint/config";
import importEsmPlugin from 'eslint-plugin-import-esm';
export default defineConfig([
{
plugins: { 'import-esm': importEsmPlugin },
rules: {
'import-esm/explicit-extension': ['error', { extension: '.mjs' }]
}
}
]);
`
💼 Configurations enabled in.\
✅ Set in the recommended configuration.\--fix
🔧 Automatically fixable by the CLI option.
| Name | Description | 💼 | 🔧 |
| :----------------------------------------------------- | :------------------------------------------------------------- | :- | :- |
| explicit-extension | Validate if import and export paths have an explicit extension | ✅ | 🔧 |
| | Name |
| :- | :------------ |
| ✅ | recommended` |