named
Added in v0.9.4Configuration
Rule Details
Require named imports and re-exports to exist in the referenced module. The rule follows explicit re-exports and export * declarations, reporting a broken explicit re-export chain when necessary.
Given values.js:
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Unresolved, ignored and non-ES modules are skipped. Declaration-level type imports and exports, and inline type import specifiers, are skipped. Like upstream, inline export { type Missing } from './values.js' is checked. Default imports and namespace imports are outside this rule's scope.
Options
This rule accepts an options object with the following default:
Set commonjs to true to also check identifier keys in destructured require calls:
This option checks ES module exports consumed through require; it does not infer CommonJS exports. String keys and rest elements are skipped. The rule has no automatic fixes or suggestions.
Differences from upstream
- Imports follow the project's TypeScript module resolution settings. ESLint
resolver plugins and their custom package entry fields are not supported.
For example, a package with a
typesentry is checked against that declaration file, even if its runtime entry is CommonJS. Configure TypeScript'spathsfor a different entry point, or useimport/ignoreto exclude a package. - When both
languageOptions.parserOptions.projectandprojectServiceare disabled, only imported files also selected for linting can be checked. For example, lintingapp.tsalone does not check names exported bylib.ts. Enable either project option to check dependencies without linting them directly. - Flow
typeofimports and Babel's experimentalexport name from './module'syntax are unsupported. Use TypeScript type imports and standardexport { default as name } from './module'syntax instead. - Syntax errors in imported files are not reported by this rule. For example,
importing a file containing
return; export {};produces a parse-error report upstream, but no report from this rule. Check the imported file's syntax separately. - Given
export * as ns from './values.js', onlynsis exported. rslint reports an import ofvaluefrom that barrel; upstream v2.32.0 also exposes namespace members as named exports. Importnsand accessns.valueinstead. - Quoted re-export names are recognized. For example,
export { value as 'quoted' } from './values.js'allowsimport { quoted } from './barrel.js'in rslint, while upstream v2.32.0 reports it as missing. Removing the quotes makes both tools agree. esModuleInteropdoes not supply a missing ES module default. Givenexport const value = 1invalues.mjs, rslint reportsimport { default as value } from './values.mjs'even withesModuleInterop: true; upstream v2.32.0 allows it. Import{ value }or add a default export. With NodeNext, native ES imports of CommonJS modules still receivemodule.exportsas their default, regardless of the interop setting.