# import/no-dynamic-require

> Disallow `require()` with an argument that is not a string literal

A bundler, a type checker and the other `import/*` rules find out what a file depends on by reading the string in `require("...")`. If the argument is a variable or is built at runtime, they can't know which file is loaded. The bundle misses it, and a wrong path only fails when the line runs.

A template literal without `${}` counts as a string.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"import/no-dynamic-require" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"import/no-dynamic-require" = ["error", {
  esmodule = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
const plugin = require(name);
const locale = require(`./locales/${language}.json`);
```

Not reported:

{/* good */}
```js
const plugin = require("./plugins/markdown");
const locale = require(`./locales/en.json`);
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `esmodule` | `false` | Also check `import()`. |

{/* bad {"options": [{"esmodule": true}]} */}
```js
const locale = await import(`./locales/${language}.js`);
```

{/* good {"options": [{"esmodule": true}]} */}
```js
const locale = await import("./locales/en.js");
```

## When not to use it

A plugin loader has to load whatever its config names. Disable the rule on that line.
