# no-require-or-define

Rule `sonarjs/no-require-or-define`. "import" should be used to include external code

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2161 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-require-or-define` | no | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3533/) |

## Code examples

### Incorrect: the rule reports this

```js
// circle.js
exports.area = function (r) {
  return PI * r * r;
};

// foo.js
define(["./cart", "./horse"], function(cart, horse) {  // Noncompliant
  // ...
});

// bar.js
const circle = require('./circle.js');  // Noncompliant
```

### Correct: the rule accepts this

```js
// circle.js
let area = function (r) {
  return PI * r * r;
}
export default area;

// foo.js
import cart from "./cart.js";
import horse from "./horse.js";

// bar.js
import circle from "./circle.js"
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-require-or-define": "error",
    },
  },
];
```

## Related rules

- [sonarjs/no-reference-error](https://lintradar.dev/rules/sonarjs/no-reference-error.md): Variables should be defined before being used
- [sonarjs/no-return-type-any](https://lintradar.dev/rules/sonarjs/no-return-type-any.md): Primitive return types should be used
- [sonarjs/no-sonar-comments](https://lintradar.dev/rules/sonarjs/no-sonar-comments.md): Track uses of "NOSONAR" comments
- [sonarjs/no-networkidle-wait](https://lintradar.dev/rules/sonarjs/no-networkidle-wait.md): Playwright "networkidle" waits should not be used
- [sonarjs/no-nested-incdec](https://lintradar.dev/rules/sonarjs/no-nested-incdec.md): Increment (++) and decrement (--) operators should not be used in a method call or mixed with other operators in an expression
- [sonarjs/no-undefined-assignment](https://lintradar.dev/rules/sonarjs/no-undefined-assignment.md): "undefined" should not be assigned

---

Web page: https://lintradar.dev/rules/sonarjs/no-require-or-define. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
