Registry / testing / eslint-plugin-node-import

eslint-plugin-node-import

JSON →
library1.2.0jsnpmunverified

`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.

npm install eslint-plugin-node-import
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-NODE
E
eslint-plugin-node-import
testingjavascriptv1.2.0
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.

nodeImport
const nodeImport = require('eslint-plugin-node-import');
import nodeImport from 'eslint-plugin-node-import';
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.
configs
const flatRecommendedConfig = require('eslint-plugin-node-import').configs['flat/recommended'];
import { configs } from 'eslint-plugin-node-import';
Configurations are accessed as properties of the main CommonJS export object. The `flat/recommended` configuration is the primary preset for new flat configs.
rules
const rules = require('eslint-plugin-node-import').rules;
import { rules } from 'eslint-plugin-node-import';
Individual rules can be accessed directly from the `rules` property of the main export if manual configuration is preferred over extending presets.

Demonstrates installation and configuration using ESLint's flat config (`eslint.config.js`), extending the recommended preset and manually enabling the `prefer-node-protocol` rule.

npm i eslint eslint-plugin-node-import --save-dev // eslint.config.js (ESLint Flat Config) const nodeImport = require('eslint-plugin-node-import'); module.exports = [ // Recommended configuration for the plugin ...nodeImport.configs["flat/recommended"], { // Define language options if not already present languageOptions: { ecmaVersion: 'latest', sourceType: 'module', globals: { // Example global if needed, e.g., for browser environments // document: 'readonly', } }, // Or manually configure the rule plugins: { "node-import": nodeImport }, rules: { "node-import/prefer-node-protocol": "error" } }, // Your other ESLint configurations go here { files: ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts'], rules: { // Example of another rule you might have 'no-unused-vars': 'warn' } } ];
Debug
Known issues
gotchaWhen 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.
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.
affects: >=1.1.0
gotchaThe `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.
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.
affects: >=1.0.0
gotchaIf 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
ESLint: Definition for rule 'node-import/prefer-node-protocol' was not found (node-import/prefer-node-protocol)
The `eslint-plugin-node-import` plugin is not correctly installed or configured in your ESLint setup.
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).
Error: Cannot find module 'eslint-plugin-node-import'
The package `eslint-plugin-node-import` is not installed or not resolvable from the project root.
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.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
eslintrequiredPeer dependency for ESLint, required for plugin functionality.
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-plugin-node-import — npm install eslint-plugin-node-import · libregistry