{"id":13146,"library":"eslint-plugin-node-import","title":"ESLint Plugin for Node.js `node:` Protocol Imports","description":"`eslint-plugin-node-import` is an ESLint plugin designed to enforce the use of the `node:` protocol prefix for built-in Node.js modules, a best practice introduced in Node.js v14 to disambiguate bare module specifiers from npm packages. The current stable version is v1.2.0, which notably introduced TypeScript typings and improved support for ESLint's new flat configuration system (`eslint.config.js`). This plugin offers a singular, focused rule, `prefer-node-protocol`, providing a dedicated solution for this specific coding standard, unlike broader linting plugins that might bundle this rule among many others. It maintains an active development cadence, with several releases over the past year addressing compatibility with newer Node.js versions (up to v23.5.0+) and adding features like flat config support.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/kytta/eslint-plugin-node-import","tags":["javascript","eslint","eslintplugin","eslint-plugin","typescript"],"install":[{"cmd":"npm install eslint-plugin-node-import","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-node-import","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-node-import","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for ESLint, required for plugin functionality.","package":"eslint","optional":false}],"imports":[{"note":"The plugin is primarily designed for CommonJS `require()` in ESLint configuration files (e.g., `eslint.config.js` or `.eslintrc.js`). While TypeScript typings are provided, the runtime export remains a CommonJS module.","wrong":"import nodeImport from 'eslint-plugin-node-import';","symbol":"nodeImport","correct":"const nodeImport = require('eslint-plugin-node-import');"},{"note":"Configurations are accessed as properties of the main CommonJS export object. The `flat/recommended` configuration is the primary preset for new flat configs.","wrong":"import { configs } from 'eslint-plugin-node-import';","symbol":"configs","correct":"const flatRecommendedConfig = require('eslint-plugin-node-import').configs['flat/recommended'];"},{"note":"Individual rules can be accessed directly from the `rules` property of the main export if manual configuration is preferred over extending presets.","wrong":"import { rules } from 'eslint-plugin-node-import';","symbol":"rules","correct":"const rules = require('eslint-plugin-node-import').rules;"}],"quickstart":{"code":"npm i eslint eslint-plugin-node-import --save-dev\n\n// eslint.config.js (ESLint Flat Config)\nconst nodeImport = require('eslint-plugin-node-import');\n\nmodule.exports = [\n  // Recommended configuration for the plugin\n  ...nodeImport.configs[\"flat/recommended\"],\n  {\n    // Define language options if not already present\n    languageOptions: {\n      ecmaVersion: 'latest',\n      sourceType: 'module',\n      globals: {\n        // Example global if needed, e.g., for browser environments\n        // document: 'readonly',\n      }\n    },\n    // Or manually configure the rule\n    plugins: {\n      \"node-import\": nodeImport\n    },\n    rules: {\n      \"node-import/prefer-node-protocol\": \"error\"\n    }\n  },\n  // Your other ESLint configurations go here\n  {\n    files: ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts'],\n    rules: {\n      // Example of another rule you might have\n      'no-unused-vars': 'warn'\n    }\n  }\n];\n","lang":"javascript","description":"Demonstrates installation and configuration using ESLint's flat config (`eslint.config.js`), extending the recommended preset and manually enabling the `prefer-node-protocol` rule."},"warnings":[{"fix":"For `eslint.config.js`, always use `const plugin = require('eslint-plugin-node-import');`. For `.eslintrc.js`, ensure it's a CommonJS file and configure via `plugins` and `extends` arrays.","message":"When migrating from older ESLint configurations (`.eslintrc.*`) to the new flat config (`eslint.config.js`), ensure you use the correct import method (`require` vs `import`) and access the plugin's configurations appropriately. The plugin itself exports a CommonJS module, as shown in its `eslint.config.js` examples.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Use ESLint's `overrides` configuration to apply the `node-import/prefer-node-protocol` rule only to files intended for Node.js environments, or disable it for browser-specific code.","message":"The `node:` protocol prefix is primarily beneficial for Node.js environments and might not be applicable or desirable for browser-only JavaScript or environments that don't differentiate Node.js built-ins. Ensure the rule is only applied where appropriate to avoid unnecessary linting errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review your ESLint configuration for duplicate rules. Disable `node-import/prefer-node-protocol` if `eslint-plugin-unicorn`'s equivalent rule is already active and sufficient, or vice-versa.","message":"If you are already using a broader linting plugin like `eslint-plugin-unicorn`, it might include a similar rule (e.g., `unicorn/prefer-node-protocol`). Using both plugins with the same rule enabled could lead to redundant checks or configuration conflicts.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure `eslint-plugin-node-import` is installed (`npm install eslint-plugin-node-import --save-dev`) and added to the `plugins` array in your ESLint configuration (e.g., `plugins: [\"node-import\"]` for legacy config or `plugins: {\"node-import\": nodeImport}` for flat config).","cause":"The `eslint-plugin-node-import` plugin is not correctly installed or configured in your ESLint setup.","error":"ESLint: Definition for rule 'node-import/prefer-node-protocol' was not found (node-import/prefer-node-protocol)"},{"fix":"Run `npm install eslint-plugin-node-import --save-dev` to install the package. Verify that ESLint is being run from a directory where `node_modules` is accessible.","cause":"The package `eslint-plugin-node-import` is not installed or not resolvable from the project root.","error":"Error: Cannot find module 'eslint-plugin-node-import'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}