prefer-export-from
March 27, 2026 · View on GitHub
📝 Prefer export…from when re-exporting.
💼🚫 This rule is enabled in the ✅ recommended config. This rule is disabled in the ☑️ unopinionated config.
🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
When re-exporting from a module, it's unnecessary to import and then export. It can be done in a single export…from declaration.
Examples
// ❌
import defaultExport from './foo.js';
export default defaultExport;
// ✅
export {default} from './foo.js';
// ❌
import {named} from './foo.js';
export {named};
// ✅
export {named} from './foo.js';
// ❌
import * as namespace from './foo.js';
export {namespace};
// ✅
export * as namespace from './foo.js';
// ❌
import defaultExport, {named} from './foo.js';
export default defaultExport;
export {
defaultExport as renamedDefault,
named,
named as renamedNamed,
};
// ✅
export {
default,
default as renamedDefault,
named,
named as renamedNamed,
} from './foo.js';
// ✅
// There is no substitution
import * as namespace from './foo.js';
export default namespace;
Options
ignoreUsedVariables
Type: boolean
Default: false
When true, if an import is used in other places than just a re-export, all variables in the import declaration will be ignored.
/* eslint unicorn/prefer-export-from: ["error", {"ignoreUsedVariables": false}] */
// ❌
import {named1, named2} from './foo.js';
use(named1);
export {named1, named2};
/* eslint unicorn/prefer-export-from: ["error", {"ignoreUsedVariables": true}] */
// ✅
import {named1, named2} from './foo.js';
use(named1);
export {named1, named2};