Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 2.52 KB

no-missing-import.md

File metadata and controls

88 lines (60 loc) · 2.52 KB

Disallow import declarations which import non-existence modules (n/no-missing-import)

💼 This rule is enabled in the following configs: 🟢 recommended-module, ✅ recommended-script.

This is similar to no-missing-require, but this rule handles import and export declarations.

📖 Rule Details

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";

Options

{
    "rules": {
        "n/no-missing-import": ["error", {
            "allowModules": [],
            "resolvePaths": ["/path/to/a/modules/directory"]
        }]
    }
}

allowModules

This can be configured in the rule options or as a shared setting settings.allowModules. Please see the shared settings documentation for more information.

resolvePaths

This can be configured in the rule options or as a shared setting settings.resolvePaths. Please see the shared settings documentation for more information.

tsconfigPath

This can be configured in the rule options or as a shared setting settings.tsconfigPath. Please see the shared settings documentation for more information.

typescriptExtensionMap

This can be configured in the rule options or as a shared setting settings.typescriptExtensionMap. Please see the shared settings documentation for more information.

ignoreTypeImport

If using typescript, you may want to ignore type imports.

{
    "rules": {
        "n/no-missing-import": ["error", {
            "ignoreTypeImport": true
        }]
    }
}

In this way, the following code will not be reported:

import type { TypeOnly } from "@types/only-types";

🔎 Implementation