Open andersk opened 1 week ago
This plugin uses resolve
, which doesn't yet support the exports
field.
prettier's main
points to https://unpkg.com/prettier@3.3.3/index.cjs, which is a CJS file with a single default export.
In other words, as far as the plugin's concerned, you'd need to import prettier from 'prettier'
. In node, the native import would point to https://unpkg.com/browse/prettier@3.3.3/index.mjs, which seems to support that same pattern (it would also work with import * as
, of course)
What happens if you change how you're importing it?
I tried that above:
Similarly, on
import prettier from "prettier";
, theimport/default
rule complains ‘No default export found in imported module "prettier"’.
$ npx eslint foo.mjs
/tmp/test/foo.mjs
1:8 error No default export found in imported module "prettier" import/default
✖ 1 problem (1 error, 0 warnings)
aha, well then that's certainly not a viable workaround :-)
Also, the plugin does not complain about import * as
on other CJS-only modules. (At runtime, such an import
causes Node to create a namespace wrapper with a default
key, and possibly other keys via cjs-module-lexer.)
It's likely some complex interaction with the combination of main
, module
, exports
, and ESM-transpiled output used in prettier specifically.
In an ESM project (
.mjs
or"type": "module"
), eslint-plugin-import can’t find any exports in theprettier
package. Onimport * as prettier from "prettier";
, theimport/namespace
rule complains “No exported names found in module 'prettier'”. Similarly, onimport prettier from "prettier";
, theimport/default
rule complains ‘No default export found in imported module "prettier"’.Complete reproducible example:
eslint.config.mjs
foo.mjs