eslint-plugin-import-exports-imports-resolver

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

A custom resolver for eslint-plugin-import that resolves package exports and imports defined in the exports and imports fields of package.json. Version 1.0.1 is the only published version. It eliminates false positives for import/no-unresolved when using package.json exports and imports (e.g., #imports or subpath exports). Different from the default node resolver, which does not support these fields. Supports aliases and custom module directories. Works with both CJS and ESM configs, but requires eslint-plugin-import to be installed. No known alternative resolvers for this specific use case.

error Unable to resolve path to module 'eslint-plugin-import-exports-imports-resolver'
cause In JSON config, the package name is used instead of the full path to index.js.
fix
Replace 'eslint-plugin-import-exports-imports-resolver' with './node_modules/eslint-plugin-import-exports-imports-resolver/index.js' in settings.import/resolver.
error Cannot find module 'eslint-plugin-import'
cause eslint-plugin-import is not installed.
fix
Run 'npm install eslint-plugin-import --save-dev'.
error Expected 'import/resolver' to be an object, got undefined
cause settings.import is not defined in ESLint config.
fix
Add a settings object with 'import' key: settings: { 'import': { resolver: { ... } } }.
error import/no-unresolved: Unable to resolve path to module '#foo'
cause The 'imports' field in package.json is missing or incorrectly configured.
fix
Ensure your package.json has an 'imports' field mapping '#foo' to a valid path, e.g., { "imports": { "#foo": "./bar.js" } }.
gotcha JSON config requires full path to index.js, not package name.
fix Use './node_modules/eslint-plugin-import-exports-imports-resolver/index.js' instead of the package name.
gotcha Package is CJS-only; ESM imports may not work.
fix Use require() instead of import.
gotcha Must have eslint-plugin-import installed and configured.
fix Install eslint-plugin-import and configure it with import/no-unresolved rule enabled.
gotcha Alias configuration requires exact path matching; wildcards not supported.
fix Use explicit alias mappings, e.g., 'project-foo' -> 'project-foo-v1'.
npm install eslint-plugin-import-exports-imports-resolver
yarn add eslint-plugin-import-exports-imports-resolver
pnpm add eslint-plugin-import-exports-imports-resolver

Configures the resolver in a .eslintrc.js file with an alias and custom module directories, enabling resolution of package imports and exports.

// .eslintrc.js
module.exports = {
  settings: {
    'import/resolver': {
      [require.resolve('eslint-plugin-import-exports-imports-resolver')]: {
        alias: {
          'my-alias': 'my-alias-v2'
        },
        node: {
          moduleDirectory: ['node_modules', 'bower_components']
        }
      },
    },
  },
  rules: {
    'import/no-unresolved': 'error',
  },
};

// Then in your source files:
import { foo } from '#local'; // resolves via imports field
import { bar } from 'pkg/subpath'; // resolves via exports field