Registry / testing / eslint-plugin-require-extensions

eslint-plugin-require-extensions

JSON →
library0.1.3jsnpmunverified

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.

npm install eslint-plugin-require-extensions
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-REQU
E
eslint-plugin-require-extensions
testingjavascriptv0.1.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugins
"plugins": [ "require-extensions" ]
"plugins": [ "eslint-plugin-require-extensions" ]
When configuring ESLint, plugins are referenced by their short name after 'eslint-plugin-' prefix. Do not include the full package name.
extends (recommended)
"extends": [ "plugin:require-extensions/recommended" ]
"extends": [ "require-extensions/recommended" ]
The 'recommended' configuration preset should be referenced with the 'plugin:' prefix, followed by the short plugin name.
rules (individual)
"rules": { "require-extensions/require-extensions": "error" }
"rules": { "require-extensions": "error" }
To configure individual rules, prepend the plugin's short name (e.g., 'require-extensions') to the rule name.

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
Debug
Known issues
gotchaTypeScript's default behavior does not enforce or transform file extensions for relative imports, which can lead to runtime errors, especially in Node.js ESM environments that require explicit '.js' extensions. This plugin directly addresses that gap.
fix
Ensure the plugin is correctly installed and configured in your `.eslintrc` file, using either the `recommended` preset or explicitly enabling the `require-extensions/require-extensions` rule.
affects: >=0.1.0
gotchaUsing this plugin in a mixed CommonJS/ESM codebase might lead to linting errors for CommonJS files if they use relative imports without `.js` extensions, even though CommonJS typically doesn't strictly require them. This plugin is primarily aimed at ESM consistency.
fix
Consider using ESLint overrides in your `.eslintrc` to disable or relax this rule for specific CommonJS files or directories if they are not intended to comply with ESM extension rules. Alternatively, ensure all relative imports in both CJS and ESM code conform to the `.js` extension for consistency.
affects: >=0.1.0
Errors
Common errors & fixes
Relative imports and exports must end with .js require-extensions/require-extensions
A relative import or export statement is missing the '.js' file extension.
fix
Add the '.js' extension to all relative import and export paths (e.g., change `import Foo from './bar'` to `import Foo from './bar.js'`). You can run `eslint --fix .` to automatically fix most of these issues.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies
eslintrequiredThis is an ESLint plugin and requires ESLint as a peer dependency to function.
Agent activity
2 hits · last 30 days
node
2
Resources
eslint-plugin-require-extensions — npm install eslint-plugin-require-extensions · libregistry