- Instant help with your JavaScript coding problems

Fix: Require statement not part of import statement

During JavaScript development, you may encounter the following ESLint error message: 

ESLint: Require statement not part of import statement.(@typescript-eslint/no-var-requires)

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.

Solution

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 */

 

Reference

ESLint no-var-requires rule reference

Source code of no-var-requires rule

 

Share "Fix: Require statement not part of import statement" with your friends