source: frontend/node_modules/eslint-plugin-import/docs/rules/no-dynamic-require.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 780 bytes
Line 
1# import/no-dynamic-require
2
3<!-- end auto-generated rule header -->
4
5The `require` method from CommonJS is used to import modules from different files. Unlike the ES6 `import` syntax, it can be given expressions that will be resolved at runtime. While this is sometimes necessary and useful, in most cases it isn't. Using expressions (for instance, concatenating a path and variable) as the argument makes it harder for tools to do static code analysis, or to find where in the codebase a module is used.
6
7This rule forbids every call to `require()` that uses expressions for the module name argument.
8
9## Rule Details
10
11### Fail
12
13```js
14require(name);
15require('../' + name);
16require(`../${name}`);
17require(name());
18```
19
20### Pass
21
22```js
23require('../name');
24require(`../name`);
25```
Note: See TracBrowser for help on using the repository browser.