ESLint Plugin for .js Extension Enforcement

0.1.3 · active · verified Wed Apr 22

The `eslint-plugin-require-extensions` package provides a straightforward ESLint plugin designed to ensure that relative import and export paths consistently include the `.js` file extension. This plugin addresses a specific pain point in TypeScript development where TypeScript itself does not automatically transform file extensions nor strictly enforce their presence in module resolution, particularly problematic for environments that require explicit extensions for ESM, such as Node.js. The current stable version is `0.1.3`, indicating an early stage of development, likely with infrequent releases focused on stability and specific enhancements. Its primary differentiator is its singular focus on this `.js` extension problem, providing a targeted and effective solution for projects aiming for full ESM compatibility and consistent module resolution across different environments. It's a pragmatic tool for maintaining import consistency that TypeScript currently leaves unaddressed, helping prevent runtime errors related to module resolution.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart installs the plugin, configures it in `.eslintrc.json` using the recommended rules, demonstrates correct and incorrect import syntax, and shows how to lint and fix issues.

npm install --save-dev eslint-plugin-require-extensions

// .eslintrc.json
{
    "root": true,
    "env": {
        "node": true
    },
    "extends": [
        "plugin:require-extensions/recommended"
    ],
    "plugins": [
        "require-extensions"
    ],
    "parserOptions": {
      "ecmaVersion": "latest",
      "sourceType": "module"
    }
}

// src/index.ts (example file)
// import SomeModule from './some-module'; // This would trigger an error
import OtherModule from './other-module.js'; // This is correct

// To run the linter and fix errors:
npx eslint src --fix

view raw JSON →