Node default behavior import resolution plugin for eslint-plugin-import.
npx @tessl/cli install tessl/npm-eslint-import-resolver-node@0.3.0ESLint Import Resolver Node provides Node.js-style module resolution for eslint-plugin-import. It implements the default Node.js module resolution algorithm to help ESLint's import plugin understand how to locate and validate import statements in JavaScript code, including support for ES6 modules through package.json fields.
npm install eslint-import-resolver-nodeconst resolver = require("eslint-import-resolver-node");For ESM environments:
import * as resolver from "eslint-import-resolver-node";This resolver is designed to be used as a plugin for eslint-plugin-import. It is configured in ESLint settings:
# Basic configuration
settings:
import/resolver: nodeWith custom options:
settings:
import/resolver:
node:
extensions:
- .js
- .jsx
- .es6
- .coffee
paths:
- /usr/local/share/global_modules
moduleDirectory:
- node_modules
- bower_componentsIndicates the resolver API compatibility version.
/**
* Interface version number indicating resolver API compatibility
* @type {number}
*/
exports.interfaceVersion = 2;Main resolver function that attempts to resolve a module import using Node.js resolution algorithm.
/**
* Resolves a module import using Node.js resolution algorithm
* @param {string} source - The module specifier to resolve (e.g., 'lodash', './utils')
* @param {string} file - The absolute path of the file containing the import
* @param {object} config - Configuration options passed to the resolver
* @returns {object} Resolution result with found and path properties
*/
exports.resolve = function (source, file, config);Resolution Result:
interface ResolverResult {
/** Whether the module was successfully resolved */
found: boolean;
/** Absolute path to resolved module, or null for core modules */
path: string | null;
}Configuration Options:
interface ResolverConfig {
/** Array of file extensions to resolve (default: ['.mjs', '.js', '.json', '.node']) */
extensions?: string[];
/** Array of additional search paths (like NODE_PATH) */
paths?: string[];
/** Array of directory names to search for modules (default: ['node_modules']) */
moduleDirectory?: string[];
}Behavior:
{ found: true, path: null } for Node.js core modules (fs, path, etc.){ found: true, path: resolvedPath } for successfully resolved modules{ found: false } when resolution failspkg.module field over pkg.main in package.json for ES6 modulespkg['jsnext:main'] if pkg.module resolution failsUsage Example:
const resolver = require("eslint-import-resolver-node");
// Resolve a relative import
const result = resolver.resolve("./utils", "/app/src/index.js", {
extensions: [".js", ".jsx"]
});
if (result.found) {
console.log("Module resolved to:", result.path);
} else {
console.log("Module not found");
}
// Resolve a core module
const coreResult = resolver.resolve("fs", "/app/src/index.js", {});
console.log(coreResult); // { found: true, path: null }The resolver relies on these key dependencies:
Enable debug logging:
DEBUG=eslint-plugin-import:resolver:node eslint src/