🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

eslint-plugin-import-exports-imports-resolver

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-import-exports-imports-resolver

Resolve package exports and package imports in eslint-plugin-import

1.0.1
latest
Source
npm
Version published
Weekly downloads
14K
15.76%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-import-exports-imports-resolver

eslint-plugin-import currently doesn't support resolving package exports and imports. This package implements a custom resolver that supports package exports and package imports. This means you'll have no more annoying import/no-unresolved errors that are incorrectly failing, and other unwanted errors.

You can customize eslint-plugin-imports resolver by adding the following code to your eslint config:

eslint-config.js:

module.exports = {
  /** etc */

  settings: {
    'import/resolver': {
      [require.resolve('eslint-plugin-import-exports-imports-resolver')]: {},
    },
  },
};

Or if your eslint config is in JSON:

{
  /** etc */
  "settings": {
    "import/resolver": {
      "./node_modules/eslint-plugin-import-exports-imports-resolver/index.js": {}
    }
  }
}

Supported

Imports

If you specify a imports field in your working projects package.json, the resolver will try to match any import that starts with a # to the imports you specified.

./package.json:

{
  "#foo": "./bar.js"
}

./my-project.js:

import { foo } from '#foo'; // ✅ resolves to "./bar.js"

Exports

If you use third party packages that makes use of package exports, the plugin will try to resolve those imports based on the exports defined in that package.

./my-project.js:

import { foo } from 'foo/bar'; // ✅ resolves to "node_modules/foo/baz.js"

node_modules/foo/package/json:

{
  "exports": {
    "./foo/bar": "./baz.js"
  }
}

Configuration

You can also provide aliases:

eslint-config.js:

module.exports = {
  /** etc */

  settings: {
    'import/resolver': {
      [require.resolve('eslint-plugin-import-exports-imports-resolver')]: {
        alias: {
          /** Rewrite `project-foo` to `project-foo-v1` */
          'project-foo': 'project-foo-v1',
          /** Rewrite `project-bar` to `project-bar-v1` if it is requested from moduleDirectory `bower_components` */
          'project-bar': {
            alias: 'project-bar-v1',
            fromModuleDirectory: 'bower_components'
          }
        },
        node: {
          moduleDirectory: ['node_modules', 'bower_components'],
        },
      },
    },
  },
};

Keywords

eslint

FAQs

Package last updated on 02 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts