This error can appear, among others, in the webpack.config.js file of a React / TypeScipt-based web project. In this case, the project uses ES6 modules, but the webpack and its configuration file use
require , which is typically used with NodeJS to read and execute CommonJS modules.
Since the rule is useful for the project as a whole, it is not recommended to turn it off globally. Instead, it is recommended to disable the ESLint rule at the file level. So sticking with our example, add the following line to the beginning of the webpack.config.js file:
/* eslint-disable @typescript-eslint/no-var-requires */