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.
More Details
Section titled “More Details”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.
Examples
Section titled “Examples”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" } }}{ "exports": { ".": "./index.js", "./utils": "./utils.js" }}With prefer: “implicit”
Section titled “With prefer: “implicit””{ "exports": { ".": "./index.js" }}{ "exports": { ".": { "import": "./index.mjs", "require": "./index.cjs" } }}{ "exports": "./index.js"}{ "exports": { "import": "./index.mjs", "require": "./index.cjs" }}{ "exports": { ".": "./index.js", "./utils": "./utils.js" }}Options
Section titled “Options”| Name | Description | Type | Choices | Default |
|---|---|---|---|---|
prefer |
Specifies which exports format to enforce. | String | implicit, explicit |
explicit |
prefer
Section titled “prefer”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" } ]}When Not to Use It
Section titled “When Not to Use It”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.
Related Rules
Section titled “Related Rules”require-exports- Enforces that theexportsproperty is present.valid-exports- Enforces that theexportsproperty is valid.