Registry / devops / eslint-import-resolver-lerna

eslint-import-resolver-lerna

JSON →
library2.0.0jsnpmunverified

Resolver for eslint-plugin-import that enables module resolution in Lerna-based monorepos. Version 2.0.0 (latest, Nov 2020) is a rewrite to TypeScript with breaking changes from 1.x. It maps packages defined in Lerna's packages directories so that eslint-plugin-import can resolve cross-package imports, particularly needed when using compilation pipelines (Babel, TypeScript) that output to a different directory. Unlike the built-in Node resolver, this supports non-standard packages directories and helps avoid "Unable to resolve path to module" errors in monorepos.

npm install eslint-import-resolver-lerna
INSTALL
IMPORT
SIG · ESLINT-IMPORT-RESO
E
eslint-import-resolver-lerna
devopsjavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import resolver from 'eslint-import-resolver-lerna'
✗ const resolver = require('eslint-import-resolver-lerna')
ESM-only since v2; CJS require will not work with default export.
resolveSync
✓ import { resolveSync } from 'eslint-import-resolver-lerna'
✗ import { resolve } from 'eslint-import-resolver-lerna'
resolveSync is the named export for synchronous resolution; resolve does not exist.
resolve
✓ import { resolve } from 'eslint-import-resolver-lerna'
✗ import { resolve as syncResolve } from 'eslint-import-resolver-lerna'
resolve is a named export returning a promise (async). Not to be confused with resolveSync.

Configure eslint-plugin-import to use lerna resolver for packages directory.

// .eslintrc.js module.exports = { settings: { 'import/resolver': { 'eslint-import-resolver-lerna': { packages: __dirname + '/packages' } } } };
Debug
Known issues
breakingVersion 2.0.0 drops CommonJS support; package is now ESM-only.
fix
Use import syntax; if you need CJS, stay on 1.x or use dynamic import.
affects: >=2.0.0
breakingThe default export changed from a function to an object in v2.0.0.
fix
Use named exports: import { resolve, resolveSync } from the package.
affects: >=2.0.0
deprecatedThe 'packages' option no longer accepts relative paths in some ESLint contexts.
fix
Always use absolute paths, e.g., path.resolve(__dirname, 'packages').
affects: >=1.1.0
gotchaThe resolver expects package.json files in the packages subdirectories; missing ones cause silent failures.
fix
Ensure every package subdirectory has a package.json with a valid 'name' field.
affects: >=1.0.0
gotchaThe resolver does not automatically detect Lerna's lerna.json; 'packages' option is mandatory.
fix
Always specify the 'packages' setting pointing to the packages directory.
affects: >=1.0.0
Errors
Common errors & fixes
Unable to resolve path to module './packages/foo'.
eslint-plugin-import cannot find the internal package without the resolver.
fix
Add the lerna resolver configuration in .eslintrc as shown in quickstart.
Error: Cannot find module 'eslint-import-resolver-lerna'
Missing or misconfigured peer dependency eslint-plugin-import.
fix
Install eslint-plugin-import as a dev dependency: npm i -D eslint-plugin-import
TypeError: resolver.create is not a function
Using require() for v2 which is ESM-only.
fix
Change to import syntax in an ESM context or downgrade to v1.
The "packages" option must be a string or array of strings.
Invalid type passed to packages option.
fix
Ensure packages is a string path or array of absolute paths.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
eslint-plugin-importrequiredpeer dependency: the resolver is used by this plugin
lernaoptionaloptional: only needed if using Lerna for monorepo management
Agent activity
4 hits · last 30 days
node
4
Resources
eslint-import-resolver-lerna — npm install eslint-import-resolver-lerna · libregistry