Menu
Urgent
React2Shell security update

forbidden-imports

Last updated March 4, 2025

Conformance is available on Enterprise plans

The rule type enables you to disallow one or more files from importing one or more predefined modules.

Unlike , this rule type won't check for indirect (transitive) dependencies. This makes this rule faster, but limits its effectiveness.

  • Deprecating packages or versions
    • You want to disallow importing a deprecated package, and to recommend a different approach
  • Recommending an alternative package
    • You want to require that users import custom/wrapped methods from instead of directly from a testing library

If you want to prevent depending on a module for performance or security reasons, you should instead use the rule type.

To create a custom rule, you'll need to configure the below required properties:

PropertyTypeDescription
The custom rule's type.
The custom rule's name.
(optional)The custom rule's categories. Default is .
The error message, which is shown to users when they encounter this rule.
(optional)An optional link to show alongside the error message.
(optional)The rule description, which is shown in the Vercel Compass dashboard and included in allowlist files.
(optional)The rule severity added to the allowlists and used to calculate a project's conformance score.
An array of exact module names or glob expressions*.

*Note that paths containing square brackets need to be escaped, i.e. would become .
(optional)An array of exact module names of import names.
(optional)Added in Conformance . An optional array of exact paths or glob expressions, which restricts the paths that this custom rule applies to. This acts as the overridable default value for *.

*Note that paths containing square brackets need to be escaped, i.e. would become .
(optional)Flags default imports (i.e. ) as errors.
(optional)Flags namespace imports (i.e. ) as errors.

Note that when using alone, imports are not allowed at all from that module. When used with conditions like , the custom rule will only report an error when those conditions are also met.

The example below configures a rule named that disallows importing any package from the workspace except for . It also configures a rule that disallows importing from , but restricts that rule to the directory.

To enable this rule type, you can set the rule to , or provide the following configuration.

PropertyTypeDescription
(optional)An optional array of exact paths or glob expressions, which restricts the paths that this custom rule applies to*.

*Note that paths containing square brackets need to be escaped, i.e. would become .

The example below enables the custom rule for all files in the directory, excluding files in . In this example, the custom rule is also restricted to the and workspaces, which is optional.

;


Was this helpful?

supported.