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-extensionsVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.