no-unresolved
Added in v0.9.4Configuration
Rule Details
Report imports whose module cannot be resolved. The rule checks ES imports, re-exports, and dynamic import() calls with string literals. It ignores explicit import type and export type declarations.
Examples of incorrect code for this rule, when the target does not exist:
Examples of correct code for this rule, when existing.js exists:
The rule does not provide automatic fixes or suggestions.
Options
The ignore option is separate from settings['import/ignore']: a module can exist even when other import rules cannot parse its contents.
Resolution settings
Without import/resolver or import/resolve, imports are resolved as with ['node', 'typescript']. Imports the node resolver cannot find fall back to the typescript resolver, which follows the TypeScript project, including paths aliases, .js imports of .ts files, and package exports. The typescript resolver also accepts a module that only has a declaration file, such as an installed @types package.
The node resolver checks runtime files, including JSON and native modules. It tries .mjs, .js, .json, and .node extensions. For packages, it tries the module, jsnext:main, and main fields in that order, then falls back to index files. It does not treat an installed @types package as a runtime module. import/core-modules exempts exact module names, such as electron.
import/resolver accepts node, typescript, an object containing resolver options, or an array of resolvers tried in order. Node options include extensions, paths, moduleDirectory, and preserveSymlinks. The legacy import/resolve setting supplies Node options and selects only the node resolver when import/resolver is absent.
The typescript resolver follows the TypeScript project. Like eslint-import-resolver-typescript, it also resolves existing files that TypeScript does not load, such as ./style.css, @/style.css through tsconfig paths, or package/dist/reset.css. Package exports still apply.
Differences from upstream
- Without resolver settings, upstream uses only the
noderesolver, so TypeScriptpathsaliases,.jsimports of.tsfiles and packages that only declareexportsare reported. Set'import/resolver': 'node'to keep that behavior. - Supported resolvers are
nodeandtypescript, also accepted aseslint-import-resolver-nodeandeslint-import-resolver-typescript. For example,settings['import/resolver'] = 'webpack'reports a resolver error and unresolved imports. For bundler aliases, usetypescriptwith matchingpathsintsconfig.json, or exclude those imports with theignoreoption. - The
typescriptresolver follows the TypeScript project selected by rslint. Itsproject,alwaysTryTypes, and other resolver-specific options have no effect. For example,{ typescript: { project: 'tsconfig.app.json' } }does not select that config; uselanguageOptions.parserOptions.projectinstead. - If an
import/resolverobject contains several resolver names, they are tried alphabetically. Use an array, such as['typescript', 'node'], to choose the order explicitly. - Babel's experimental
export value from './module'syntax is not supported. Useexport { default as value } from './module'instead.