eslint-module-utils

raw JSON →
2.12.1 verified Sat Apr 25 auth: no javascript

eslint-module-utils (v2.12.1) provides core utilities for eslint-plugin-import and other module-related ESLint plugins. It includes helpers for parsing module resolution, resolving module paths, and managing module caches. Released under the MIT license, it supports Node >=4 and is maintained as part of the eslint-plugin-import ecosystem. Key differentiators: it is the foundational utility package powering eslint-plugin-import's module resolution, cache, and parsing features, and is used by plugins like eslint-plugin-import, eslint-plugin-node, and eslint-plugin-import-access.

error Cannot find module 'eslint-module-utils'
cause Missing dependency in package.json
fix
npm install eslint-module-utils --save-dev
error Uncaught Error: Cannot find module 'doctrine'
cause Peer dependency doctrine not installed
fix
npm install doctrine --save-dev
error TypeError: ModuleCache is not a constructor
cause Incorrect import: using default import when ModuleCache is a named export
fix
Use correct import: import { ModuleCache } from 'eslint-module-utils'
breaking ModuleCache constructor now requires options object in v3+
fix Pass an options object to the ModuleCache constructor, e.g., new ModuleCache({ cache: true }).
deprecated parse function is deprecated in v2.12.1, use parseForESLint from @typescript-eslint/parser instead
fix Migrate to parseForESLint from @typescript-eslint/parser if using TypeScript.
gotcha resolve does not support all Node.js resolution algorithms (e.g., exports map)
fix Use the enhanced-resolve package or rely on eslint-plugin-import's resolver for modern resolution.
npm install eslint-module-utils
yarn add eslint-module-utils
pnpm add eslint-module-utils

Creates a ModuleCache instance, sets a resolved path for module 'fs', and retrieves it.

import { ModuleCache } from 'eslint-module-utils';
const cache = new ModuleCache();
// Use the cache to store and retrieve module resolution results
cache.set('fs', { path: '/usr/lib/node_modules/fs' });
const result = cache.get('fs');
console.log(result?.path); // '/usr/lib/node_modules/fs'