💼 This rule is enabled in the following configs: 🟢 flat/recommended-module
, ✅ flat/recommended-script
, ☑️ recommended
, 🟢 recommended-module
, ✅ recommended-script
.
This is similar to no-missing-require, but this rule handles import
and export
declarations.
This rule checks the file paths of import
and export
declarations.
If the file paths don't exist, this reports these.
Examples of 👎 incorrect code for this rule:
/*eslint n/no-missing-import: "error" */
import typoFile from "./typo-file"; /*ERROR: "./typo-file" is not found.*/
import typoModule from "typo-module"; /*ERROR: "typo-module" is not found.*/
Examples of 👍 correct code for this rule:
/*eslint n/no-missing-import: "error" */
import existingFile from "./existing-file";
import existingModule from "existing-module";
{
"rules": {
"n/no-missing-import": ["error", {
"allowModules": [],
"resolvePaths": ["/path/to/a/modules/directory"]
}]
}
}
Some platforms have additional embedded modules.
For example, Electron has electron
module.
We can specify additional embedded modules with this option. This option is an array of strings as module names.
{
"rules": {
"n/no-missing-import": ["error", {
"allowModules": ["electron"]
}]
}
}
Adds additional paths to try for when resolving imports. If a path is relative, it will be resolved from CWD.
Default is []
Adds the ability to change the extension mapping when converting between typescript and javascript
Default is:
[
[ "", ".js" ],
[ ".ts", ".js" ],
[ ".cts", ".cjs" ],
[ ".mts", ".mjs" ],
[ ".tsx", ".jsx" ],
]
The following options can be set by shared settings. Several rules have the same option, but we can set this option at once.
allowModules
resolvePaths
typescriptExtensionMap
// .eslintrc.js
module.exports = {
"settings": {
"node": {
"allowModules": ["electron"],
"resolvePaths": [__dirname],
"typescriptExtensionMap": [
[ "", ".js" ],
[ ".ts", ".js" ],
[ ".cts", ".cjs" ],
[ ".mts", ".mjs" ],
[ ".tsx", ".js" ],
]
}
},
"rules": {
"n/no-missing-import": "error"
}
}