---
# Don't modify this file manually. This file is auto generated from source, and you will lose your changes next time the website is built.
# Head to the `biomejs/biome` repository, and modify the source code in there.

title: noRestrictedImports
description: Learn more about noRestrictedImports
---
import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs>
<TabItem label="JavaScript (and super languages)" icon="seti:javascript">
## Summary
- Rule available since: `v1.6.0`
- Diagnostic Category: [`lint/style/noRestrictedImports`](/reference/diagnostics#diagnostic-category)
- This rule isn't recommended, so you need to enable it.
- This rule doesn't have a fix.
- The default severity of this rule is [**warning**](/reference/diagnostics#warning).
- Sources: 
  - Same as [`no-restricted-imports`](https://eslint.org/docs/latest/rules/no-restricted-imports)
  - Same as [`@typescript-eslint/no-restricted-imports`](https://typescript-eslint.io/rules/no-restricted-imports)

## How to configure
```json title="biome.json"
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": "error"
			}
		}
	}
}

```
## Description
Disallow specified modules when loaded by import or require.

## Examples

```json
{
    "noRestrictedImports": {
        "options": {
            "paths": {
                "lodash": "Using lodash is not encouraged",
                "underscore": "Using underscore is not encouraged"
            }
        }
    }
}
```

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"paths": {
							"lodash": "Using lodash is not encouraged.",
							"underscore": "",
							"import-foo": {
								"importNames": [
									"Bar"
								]
							},
							"import-bar": {
								"allowImportNames": [
									"Bar"
								]
							}
						},
						"patterns": [
							{
								"group": [
									"import-foo/*",
									"!import-foo/bar"
								]
							}
						]
					}
				}
			}
		}
	}
}

```

### Invalid

```js
import "lodash";
```

<pre class="language-text"><code class="language-text">code-block.js:1:8 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Using lodash is not encouraged.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &quot;lodash&quot;;<br />   <strong>   │ </strong>       <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

```js
import "underscore";
```

<pre class="language-text"><code class="language-text">code-block.js:1:8 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'underscore'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &quot;underscore&quot;;<br />   <strong>   │ </strong>       <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

```js
import { Bar } from "import-foo";
```

<pre class="language-text"><code class="language-text">code-block.js:1:10 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'Bar' from 'import-foo'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; Bar &#125; from &quot;import-foo&quot;;<br />   <strong>   │ </strong>         <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

```js
const underscore = await import("underscore");
```

<pre class="language-text"><code class="language-text">code-block.js:1:33 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'underscore'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>const underscore = await import(&quot;underscore&quot;);<br />   <strong>   │ </strong>                                <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

```js
const lodash = require("lodash");
```

<pre class="language-text"><code class="language-text">code-block.js:1:24 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Using lodash is not encouraged.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>const lodash = require(&quot;lodash&quot;);<br />   <strong>   │ </strong>                       <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

```js
import foo from 'import-foo/foo';
```

<pre class="language-text"><code class="language-text">code-block.js:1:17 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'import-foo/foo'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import foo from 'import-foo/foo';<br />   <strong>   │ </strong>                <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

### Valid

```js
import "allowed-import";
const myImport = await import("allowed-import");
const myImport = require("allowed-import");
```

```js
import foo from 'import-foo';
import bar from 'import-foo/bar';
```

## Supported Import Syntaxes

The rule tries to parse the context of the import to see if only one or more
of the allowed import names have been imported from a given module.

All of the following import syntaxes are supported:

### Static `import` (and re-`export`) declarations

Normal static [ESM `import` declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) are supported:

```js
// Static `import` declaration:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

import "sideeffect-import";
import * as alias1 from "namespace-import";
import { export1, export2 as alias2, "string-name" as alias3, default as defaultExport /* … */ } from "named-import";
import defaultExport from "default-import";
import defaultExport, * as alias5 from "default+namespace-import";
import defaultExport, { export1 /* … */ } from "default+named-import";

export * from "namespace-import";
export { export1, export2 as alias2, "string-name" as alias3, default as defaultExport /* … */ } from "named-import";
```

The TypeScript-specific [type-only imports](https://www.typescriptlang.org/docs/handbook/modules/reference.html#type-only-imports-and-exports) are also supported:

```ts
// TypeScript-specific type-only `import` declaration:
// https://www.typescriptlang.org/docs/handbook/modules/reference.html#type-only-imports-and-exports

import { type export1, type export2 as alias2, type "string-name" as alias3, type default as defaultExport /* … */ } from "named-import";
import type { export1, export2 as alias2, "string-name" as alias3, default as defaultExport /* … */ } from "named-import";
import type defaultExport from "default-import";
```

### Dynamic `import()` calls

Dynamic [ESM `import()` calls](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) are also supported.
Because the import is performed at runtime, it is not always possible to determine which import names are being used.
Nevertheless, the rule tries to detect the following common usage patterns where the set of imported names is determined statically:

```js
// Dynamic `import()` calls:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

import('sideeffect-import');
await import('sideeffect-import');

// ...using await + destructuring-assignment:
const alias1 = await import('namespace-import');
const { default: defaultExport } = await import('default-import')
const { export1, export2: alias2, "string-name": alias3, default: defaultExport /* … */ } = await import("named-import");

// ...using then() with arrow-function + destructuring parameters:
import('namespace-import').then(alias1 => { /* … */ });
import('namespace-import').then((alias1) => { /* … */ });
import('default-import').then(({ default: defaultExport }) => { /* … */ });
import('named-import').then(({ export1, export2: alias2, "string-name": alias3, default: defaultExport /* … */ }) => { /* … */ });

// ...using then() with function + destructuring parameters:
import('namespace-import').then(function(alias1) { /* … */ });
import('default-import').then(function({ default: defaultExport }) { /* … */ });
import('named-import').then(function({ export1, export2: alias2, "string-name": alias3, default: defaultExport /* … */ }) { /* … */ });

// Standalone `import('...')` calls that appear in some other
// unrecognized context will be treated as a namespace import,
// because the return value of `import('...')` is a namespace object:

myFunction(...args, import("namespace-import"), ...args)
```

### Dynamic `require()` calls

NodeJS-style `require()` calls are also supported.
Due to the way `require()` works, these are always treated as default imports.

```js
// Dynamic `require()` call
const defaultExport = require('default-import');
```

## Options

```json
{
    "noRestrictedImports": {
        "options": {
            "paths": {
                "lodash": "Using lodash is not encouraged",
                "underscore": "Using underscore is not encouraged"
            }
        }
    }
}
```

Use the options to specify import paths and/or patterns, including specific import names, that you want to restrict in your source code.

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"paths": {
							"lodash": "Using lodash is not encouraged",
							"underscore": "Using underscore is not encouraged",
							"import-foo": {
								"importNames": [
									"Bar"
								],
								"message": "Please use Bar from /import-bar/baz/ instead."
							},
							"import-bar": {
								"allowImportNames": [
									"Bar"
								],
								"message": "Please use only Bar from import-bar."
							}
						}
					}
				}
			}
		}
	}
}

```

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"patterns": [
							{
								"group": [
									"import-foo/*",
									"!import-foo/bar"
								]
							}
						]
					}
				}
			}
		}
	}
}

```

### `paths`

An object that lists the import paths that are either wholly or partially restricted.

The keys of the object are the import paths to restrict, and the values can be:

- A string with a custom message to show in the diagnostic when any
- An object with additional options, as explained [below](#pathsimportimportnames).

In the example below, we restrict the two paths `services-deprecated` and `constants`, with two particular messages.
Importing `services-deprecated` will emit the message `Use services instead.`.
Importing `constants` will emit the message `This file will be deleted soon.`:

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"paths": {
							"services-deprecated": {
								"message": "Use services instead."
							},
							"constants": "This file will be deleted soon."
						}
					}
				}
			}
		}
	}
}

```

```js
import * as namespaceAlias from 'services-deprecated';
```

<pre class="language-text"><code class="language-text">code-block.js:1:33 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Use services instead.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#42; as namespaceAlias from 'services-deprecated';<br />   <strong>   │ </strong>                                <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

```js
import { export1 } from 'constants';
```

<pre class="language-text"><code class="language-text">code-block.js:1:25 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">This file will be deleted soon.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; export1 &#125; from 'constants';<br />   <strong>   │ </strong>                        <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

### `paths.<import>.message`

Specifies the message to be shown when the restricted import is used.

A default message will be generated if `message` is empty or not specified:

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"paths": {
							"import-foo": {}
						}
					}
				}
			}
		}
	}
}

```

```js
import { export1 } from 'import-foo';
```

<pre class="language-text"><code class="language-text">code-block.js:1:25 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'import-foo'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; export1 &#125; from 'import-foo';<br />   <strong>   │ </strong>                        <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

### `paths.<import>.importNames`

Specifies the array of import names that should be explicitly forbidden.
The following import name specifiers are supported:

- **Named import:** `"someIdentifier"` (`import { someIdentifier } from 'named-import'`)
- **Default import:** `"default"` (`import defaultExport from 'default-import'`)
- **Namespace import:** `"*"` (`import * as alias1 from 'namespace-import'`)
- **Side effect/Bare import:** `""` (`import "sideeffect-import"`)

**Only one of `importNames` and `allowImportNames` must be specified.**

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"paths": {
							"import-foo": {
								"importNames": [
									"Bar"
								],
								"message": "Please use Bar from /import-bar/baz/ instead."
							}
						}
					}
				}
			}
		}
	}
}

```

#### Invalid

```js
import { Bar } from 'import-foo';
```

<pre class="language-text"><code class="language-text">code-block.js:1:10 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Please use Bar from /import-bar/baz/ instead.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; Bar &#125; from 'import-foo';<br />   <strong>   │ </strong>         <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

#### Valid

```js
import { Foo } from 'import-foo';
```

### `paths.<import>.allowImportNames`

Specifies the set of import names that should be explicitly allowed.
See `importNames` for the set of supported import name specifiers.

**Only one of `importNames` and `allowImportNames` must be specified.**

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"paths": {
							"import-bar": {
								"allowImportNames": [
									"Bar"
								]
							},
							"restrictPackagePrivate": "all"
						}
					}
				}
			}
		}
	}
}

```

#### Invalid

```js
import { Baz } from 'import-bar';
```

<pre class="language-text"><code class="language-text">code-block.js:1:10 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'Baz' from 'import-bar'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; Baz &#125; from 'import-bar';<br />   <strong>   │ </strong>         <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Only the following imports from </span><span style="color: lightgreen;"><strong>'import-bar'</strong></span><span style="color: lightgreen;"> are allowed:</span><br />  <br />  - Bar<br />  <br /></code></pre>

#### Valid

```js
import { Bar } from 'import-bar';
```

### `patterns`

**Since `v2.2.0`**

This option allows you to specify multiple modules to restrict using gitignore-style patterns.

### `group`

The patterns array can also include objects. The group property is used to specify the gitignore-style patterns for restricting modules and the message property is used to specify a custom message.

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"patterns": [
							{
								"group": [
									"import-foo/*",
									"!import-foo/bar"
								],
								"message": "import-foo is deprecated, except the modules in import-foo/bar."
							}
						]
					}
				}
			}
		}
	}
}

```

#### Invalid

```js
import foo from 'import-foo/foo';
```

<pre class="language-text"><code class="language-text">code-block.js:1:17 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">import-foo is deprecated, except the modules in import-foo/bar.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import foo from 'import-foo/foo';<br />   <strong>   │ </strong>                <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

#### Valid

```js
import foo from 'import-foo';
import bar from 'import-foo/bar';
```

### `importNamePattern`

**Since `v2.2.0`**

This option allows you to use regex patterns to restrict import names.

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"patterns": [
							{
								"group": [
									"import-foo/*"
								],
								"importNamePattern": "[xyz]"
							}
						]
					}
				}
			}
		}
	}
}

```

#### Invalid

```js
import { x } from 'import-foo/foo';
```

<pre class="language-text"><code class="language-text">code-block.js:1:10 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'x' from 'import-foo/foo'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; x &#125; from 'import-foo/foo';<br />   <strong>   │ </strong>         <strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

#### Valid

```js
import { foo } from 'import-foo/foo';
```

### `invertImportNamePattern`

**Since `v2.2.0`**

If true, the matched patterns in the importNamePattern will be allowed

```json title='biome.json'
{
	"linter": {
		"rules": {
			"style": {
				"noRestrictedImports": {
					"options": {
						"patterns": [
							{
								"group": [
									"import-foo/*"
								],
								"importNamePattern": "[xyz]",
								"invertImportNamePattern": true
							}
						]
					}
				}
			}
		}
	}
}

```

#### Invalid

```js
import { foo } from 'import-foo/foo';
```

<pre class="language-text"><code class="language-text">code-block.js:1:10 <a href="https://biomejs.dev/linter/rules/no-restricted-imports">lint/style/noRestrictedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Do not import 'foo' from 'import-foo/foo'.</span><br />  <br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; foo &#125; from 'import-foo/foo';<br />   <strong>   │ </strong>         <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>2 │ </strong><br />  <br /></code></pre>

#### Valid

```js
import { x } from 'import-foo/foo';
```

## Related links

- [Disable a rule](/linter/#disable-a-rule)
- [Configure the code fix](/linter#configure-the-code-fix)
- [Rule options](/linter/#rule-options)
- [Source Code](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/lint/style/no_restricted_imports.rs)
- [Test Cases](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/tests/specs/style/noRestrictedImports)

</TabItem>
</Tabs>