{"id":"07f6ad78146c277f","repo":"eslint/eslint","slug":"longname-cannot-be-used-with-the-plugin-o","errorCode":null,"errorMessage":"\"${longName}\" cannot be used with the `--plugin` option because its default module does not provide a `default` export","messagePattern":"\"(.+?)\" cannot be used with the `--plugin` option because its default module does not provide a `default` export","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/translate-cli-options.js","lineNumber":45,"sourceCode":"// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * Loads plugins with the specified names.\n * @param {{ \"import\": (name: string) => Promise<any> }} importer An object with an `import` method called once for each plugin.\n * @param {string[]} pluginNames The names of the plugins to be loaded, with or without the \"eslint-plugin-\" prefix.\n * @returns {Promise<Record<string, Plugin>>} A mapping of plugin short names to implementations.\n */\nasync function loadPlugins(importer, pluginNames) {\n\tconst plugins = {};\n\n\tawait Promise.all(\n\t\tpluginNames.map(async pluginName => {\n\t\t\tconst longName = normalizePackageName(pluginName, \"eslint-plugin\");\n\t\t\tconst module = await importer.import(longName);\n\n\t\t\tif (!(\"default\" in module)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`\"${longName}\" cannot be used with the \\`--plugin\\` option because its default module does not provide a \\`default\\` export`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst shortName = getShorthandName(pluginName, \"eslint-plugin\");\n\n\t\t\tplugins[shortName] = module.default;\n\t\t}),\n\t);\n\n\treturn plugins;\n}\n\n/**\n * Predicate function for whether or not to apply fixes in quiet mode.\n * If a message is a warning, do not apply a fix.\n * @param {LintMessage} message The lint result.\n * @returns {boolean} `true` if the lint message is an error (and thus should be","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/eslint/eslint/blob/f131c034ad91bbf06bcbb6b5e931447a8e419a46/lib/shared/translate-cli-options.js#L27-L63","documentation":"Thrown by loadPlugins() in lib/shared/translate-cli-options.js:45 when a module loaded via the `--plugin` CLI option has no `default` export. ESLint's `--plugin` mechanism requires each plugin package to expose a `default` export (the plugin object); without it ESLint cannot attach the plugin. The check is `if (!(\"default\" in module))`.","triggerScenarios":"Running `eslint --plugin my-plugin` where the resolved package's entry point exports only named exports (e.g. `module.exports.rules = {...}` via CommonJS but not interpreted as default), or an ESM package that forgot `export default`. Also triggered by a plugin package whose `main`/`exports` field points at a sub-file without a default export.","commonSituations":"Upgrading a plugin to ESM and forgetting `export default`; pointing `--plugin` at a local path that re-exports named symbols; a plugin authored for an older ESLint that returned the plugin object from `module.exports` directly but is now loaded through an ESM-aware importer that sees no `default`; version mismatch between ESLint and the plugin.","solutions":["Ensure the plugin package has `export default <pluginObject>` (ESM) or `module.exports = <pluginObject>` at its entry (the module-importer treats a CJS `module.exports` as the default).","Verify the resolved entry: `node -e \"import('<pkg>').then(m => console.log('default' in m, Object.keys(m)))\"` and confirm `default` is present.","Check the plugin's package.json `main`/`exports` mapping isn't pointing at a non-default-exporting file, and pin/upgrade the plugin to a version compatible with your ESLint major.","If you only need the plugin in config, load it via the flat config `plugins` map (passing the object) instead of `--plugin`."],"exampleFix":"// before: eslint-plugin-foo/index.js (ESM, missing default)\nexport const rules = { \"my-rule\": { meta: {}, create() {} } };\n\n// after\nconst foo = { rules: { \"my-rule\": { meta: {}, create() {} } } };\nexport default foo;","handlingStrategy":"validation","validationCode":"async function assertPluginHasDefault(specifier) {\n  const mod = await import(specifier);\n  if (!(\"default\" in mod)) {\n    throw new Error(`${specifier} has no default export; cannot use with --plugin`);\n  }\n  return mod.default;\n}","typeGuard":"/** @param {unknown} m */\nfunction hasDefaultExport(m) {\n  return typeof m === \"object\" && m !== null && \"default\" in m;\n}","tryCatchPattern":"try {\n  plugins = await loadPlugins(importer, pluginNames);\n} catch (err) {\n  if (/does not provide a `default` export/.test(err.message)) {\n    // switch from --plugin to explicit flat-config plugins map\n  } else throw err;\n}","preventionTips":["Author plugins with a single `export default pluginObject` (ESM) or `module.exports = pluginObject` (CJS).","Before releasing a plugin, run `node -e \"import('my-plugin').then(m=>console.log('default' in m))\"`.","Pin plugin versions known to be compatible with your ESLint major."],"tags":["plugins","esm","cli","import","default-export"],"analyzedSha":"f131c034ad91bbf06bcbb6b5e931447a8e419a46","analyzedAt":"2026-08-03T19:53:24.025Z","schemaVersion":2}