Path: blob/main/docs/rules/no-unresolved.md
829 views
import/no-unresolved
Ensures an imported module can be resolved to a module on the local filesystem, as defined by standard Node require.resolve behavior.
See settings for customization options for the resolution (i.e. additional filetypes, NODE_PATH, etc.)
This rule can also optionally report on unresolved modules in CommonJS require('./foo') calls and AMD require(['./foo'], function (foo) {...}) and define(['./foo'], function (foo) {...}).
To enable this, send { commonjs: true/false, amd: true/false } as a rule option. Both are disabled by default.
If you are using Webpack, see the section on resolvers.
Rule Details
Options
By default, only ES6 imports will be resolved:
If {commonjs: true} is provided, single-argument require calls will be resolved:
Similarly, if { amd: true } is provided, dependency paths for define and require calls will be resolved:
Both may be provided, too:
ignore
This rule has its own ignore list, separate from import/ignore. This is because you may want to know whether a module can be located, regardless of whether it can be parsed for exports: node_modules, CoffeeScript files, etc. are all good to resolve properly, but will not be parsed if configured as such via import/ignore.
To suppress errors from files that may not be properly resolved by your resolver settings, you may add an ignore key with an array of RegExp pattern strings:
caseSensitive
By default, this rule will report paths whose case do not match the underlying filesystem path, if the FS is not case-sensitive. To disable this behavior, set the caseSensitive option to false.
caseSensitiveStrict
The caseSensitive option does not detect case for the current working directory. The caseSensitiveStrict option allows checking cwd in resolved path. By default, the option is disabled.
When Not To Use It
If you're using a module bundler other than Node or Webpack, you may end up with a lot of false positive reports of missing dependencies.
Further Reading
Node resolver (default)
import/ignoreglobal setting