or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-eslint-import-resolver-node

Node default behavior import resolution plugin for eslint-plugin-import.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/eslint-import-resolver-node@0.3.x

To install, run

npx @tessl/cli install tessl/npm-eslint-import-resolver-node@0.3.0

index.mddocs/

ESLint Import Resolver Node

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

Package Information

  • Package Name: eslint-import-resolver-node
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install eslint-import-resolver-node

Core Imports

const resolver = require("eslint-import-resolver-node");

For ESM environments:

import * as resolver from "eslint-import-resolver-node";

Basic Usage

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: node

With custom options:

settings:
  import/resolver:
    node:
      extensions:
        - .js
        - .jsx
        - .es6
        - .coffee
      paths:
        - /usr/local/share/global_modules
      moduleDirectory:
        - node_modules
        - bower_components

Capabilities

Interface Version

Indicates the resolver API compatibility version.

/**
 * Interface version number indicating resolver API compatibility
 * @type {number}
 */
exports.interfaceVersion = 2;

Module Resolution

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:

  • Returns { found: true, path: null } for Node.js core modules (fs, path, etc.)
  • Returns { found: true, path: resolvedPath } for successfully resolved modules
  • Returns { found: false } when resolution fails
  • Prioritizes pkg.module field over pkg.main in package.json for ES6 modules
  • Falls back to pkg['jsnext:main'] if pkg.module resolution fails
  • Supports configurable file extensions and module directories

Usage 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 }

Dependencies

The resolver relies on these key dependencies:

  • resolve: Core module resolution library that implements Node.js resolution algorithm
  • is-core-module: Utility to determine if a module is a Node.js core module
  • debug: Debug logging utility for troubleshooting resolution issues

Enable debug logging:

DEBUG=eslint-plugin-import:resolver:node eslint src/