require-type
💼 This rule is enabled in the following configs: ✅ recommended, 📦 recommended-publishable.
🔧 This rule is automatically fixable by the --fix CLI option.
This rule checks for the existence of the type property and reports a violation if it doesn’t exist.
Examples
Section titled “Examples”{ "name": "thee-silver-mt-zion", "version": "13.0.0"}{ "name": "Thee Silver Mt. Zion", "version": "13.0.0", "type": "module"}Options
Section titled “Options”| Name | Description | Type | Default |
|---|---|---|---|
ignorePrivate |
Determines if this rule should be enforced when the package’s private property is true. |
Boolean | false |
{ "package-json/require-type": [ "error", { "ignorePrivate": false } ]}Examples
Section titled “Examples”Example of incorrect code for this rule with the { "ignorePrivate": false } option:
{ "private": true}Examples of incorrect code for this rule with the { "ignorePrivate": true } option:
{ "private": false}{}Example of correct code for this rule with the { "ignorePrivate": false } option:
{ "private": true, "type": "module"}Example of correct code for this rule with the { "ignorePrivate": true } option:
{ "private": true}Fixing
Section titled “Fixing”This rule is automatically fixable and will add a type property, if one is missing, with the value "commonjs", which is how Node was treating the package, when no property was present.
Related Rules
Section titled “Related Rules”valid-type- Enforces that thetypeproperty is valid.