What is eslint-import-resolver-node?
The eslint-import-resolver-node package is a resolver for ESLint's import plugin that resolves node modules and paths. It is used to help ESLint understand the resolution of the import statements in a Node.js environment, ensuring that the paths to modules are correctly interpreted according to Node.js module resolution algorithms.
What are eslint-import-resolver-node's main functionalities?
Resolve Node Modules
This feature allows ESLint to resolve import statements for Node modules, taking into account file extensions like .js, .jsx, .ts, and .tsx. The code sample shows how to configure the resolver in the ESLint configuration file.
module.exports = {
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
}
}
}
};
Custom Module Directory
This feature allows the specification of custom module directories beyond the default 'node_modules'. In the code sample, 'src' is added as an additional directory to look for modules.
module.exports = {
settings: {
'import/resolver': {
node: {
moduleDirectory: ['node_modules', 'src']
}
}
}
};
Other packages similar to eslint-import-resolver-node
eslint-import-resolver-webpack
This package extends ESLint's import resolution to webpack's module resolution. It is similar to eslint-import-resolver-node but specifically tailored for projects using webpack, where the module resolution can be more complex due to webpack's aliases and other features.
eslint-import-resolver-typescript
Similar to eslint-import-resolver-node, this package is designed to resolve TypeScript modules. It is particularly useful for projects written in TypeScript, as it understands TypeScript-specific paths and module resolution.
eslint-import-resolver-babel-module
This resolver integrates with Babel's module resolver plugin. It is useful for projects that use Babel and have custom module resolution configured in their Babel settings, which might not be natively understood by ESLint.
eslint-import-resolver-node
Default Node-style module resolution plugin for eslint-plugin-import
.
Published separately to allow pegging to a specific version in case of breaking
changes.
Config is passed directly through to resolve
as options:
settings:
import/resolver:
node:
extensions:
- .js
- .jsx
- .es6
- .coffee
paths:
- /usr/local/share/global_modules
moduleDirectory:
- node_modules
- bower_components
- project/src
or to use the default options:
settings:
import/resolver: node