Skip to content

exports-subpaths-style

💼 This rule is enabled in the 🎨 stylistic config.

🔧 This rule is automatically fixable by the --fix CLI option.

This rule enforces consistent formatting for the exports property, ensuring either explicit sub-path notation with "." or implicit root-level exports.

The Node.js exports field supports two equivalent formats for defining a single root export:

Explicit format (with "." subpath):

{
"exports": {
".": "./index.js"
}
}

Implicit format (root-level value):

{
"exports": "./index.js"
}

Both formats are functionally equivalent for a single root export, but using one consistently improves readability and maintainability across packages.

With Default Options (prefer: “explicit”)

Section titled “With Default Options (prefer: “explicit”)”
{
"exports": "./index.js"
}
{
"exports": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
{
"exports": {
".": "./index.js"
}
}
{
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
Name Description Type Choices Default
prefer Specifies which exports format to enforce. String implicit, explicit explicit

The prefer option specifies which format to enforce:

  • "explicit" (default): Requires the "." subpath key for single root exports
  • "implicit": Prefers the shorthand format without "." for single root exports
{
"package-json/exports-subpaths-style": [
"error",
{
"prefer": "explicit"
}
]
}

If your project doesn’t use the exports field or you don’t have a preference for consistency in exports formatting, you can disable this rule.