{"id":16810,"library":"eslint-plugin-require-extensions","title":"ESLint Plugin for .js Extension Enforcement","description":"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.","status":"active","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/solana-labs/eslint-plugin-require-extensions","tags":["javascript"],"install":[{"cmd":"npm install eslint-plugin-require-extensions","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-require-extensions","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-require-extensions","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is an ESLint plugin and requires ESLint as a peer dependency to function.","package":"eslint","optional":false}],"imports":[{"note":"When configuring ESLint, plugins are referenced by their short name after 'eslint-plugin-' prefix. Do not include the full package name.","wrong":"    \"plugins\": [\n        \"eslint-plugin-require-extensions\"\n    ]","symbol":"plugins","correct":"    \"plugins\": [\n        \"require-extensions\"\n    ]"},{"note":"The 'recommended' configuration preset should be referenced with the 'plugin:' prefix, followed by the short plugin name.","wrong":"    \"extends\": [\n        \"require-extensions/recommended\"\n    ]","symbol":"extends (recommended)","correct":"    \"extends\": [\n        \"plugin:require-extensions/recommended\"\n    ]"},{"note":"To configure individual rules, prepend the plugin's short name (e.g., 'require-extensions') to the rule name.","wrong":"    \"rules\": {\n        \"require-extensions\": \"error\"\n    }","symbol":"rules (individual)","correct":"    \"rules\": {\n        \"require-extensions/require-extensions\": \"error\"\n    }"}],"quickstart":{"code":"npm install --save-dev eslint-plugin-require-extensions\n\n// .eslintrc.json\n{\n    \"root\": true,\n    \"env\": {\n        \"node\": true\n    },\n    \"extends\": [\n        \"plugin:require-extensions/recommended\"\n    ],\n    \"plugins\": [\n        \"require-extensions\"\n    ],\n    \"parserOptions\": {\n      \"ecmaVersion\": \"latest\",\n      \"sourceType\": \"module\"\n    }\n}\n\n// src/index.ts (example file)\n// import SomeModule from './some-module'; // This would trigger an error\nimport OtherModule from './other-module.js'; // This is correct\n\n// To run the linter and fix errors:\nnpx eslint src --fix","lang":"typescript","description":"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."},"warnings":[{"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.","message":"TypeScript'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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"Using 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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.","cause":"A relative import or export statement is missing the '.js' file extension.","error":"Relative imports and exports must end with .js  require-extensions/require-extensions"}],"ecosystem":"npm","meta_description":null}