📝 Disallow require() expressions which import missing modules.
💼 This rule is enabled in the following configs: 🟢 recommended-module, ✅ recommended-script.
Maybe we cannot find typo of import paths until run it, so this rule checks import paths.
// If the file "foo" doesn't exist, this is a runtime error.
const foo = require("./foo");This rule checks the file paths of require()s, then reports the path of files which don't exist.
Examples of 👎 incorrect code for this rule:
/*eslint n/no-missing-require: "error" */
var typoFile = require("./typo-file"); /*error "./typo-file" is not found.*/
var typoModule = require("typo-module"); /*error "typo-module" is not found.*/Examples of 👍 correct code for this rule:
/*eslint n/no-missing-require: "error" */
var existingFile = require("./existing-file");
var existingModule = require("existing-module");
// This rule cannot check for dynamic imports.
var foo = require(FOO_NAME);{
"rules": {
"n/no-missing-require": ["error", {
"allowModules": [],
"resolvePaths": ["/path/to/a/modules/directory"],
"tryExtensions": [".js", ".json", ".node"]
}]
}
}This can be configured in the rule options or as a shared setting settings.allowModules.
Please see the shared settings documentation for more information.
This can be configured in the rule options or as a shared setting settings.resolvePaths.
Please see the shared settings documentation for more information.
This can be configured in the rule options or as a shared setting settings.resolverConfig.
Please see the shared settings documentation for more information.
This can be configured in the rule options or as a shared setting settings.tryExtensions.
Please see the shared settings documentation for more information.
This can be configured in the rule options or as a shared setting settings.tsconfigPath.
Please see the shared settings documentation for more information.
This can be configured in the rule options or as a shared setting settings.typescriptExtensionMap.
Please see the shared settings documentation for more information.