I am getting the error below on running the eslint.
\helpers\getEnvCredentials.ts 4:9 error Require statement not part of import statement @typescript-eslint/no-var-requires
✖ 1 problem (1 error, 0 warnings)
That error is referring to these lines of code wherein it is saying that using the "require" statement should be use only on imports. Please see (https://typescript-eslint.io/rules/no-var-requires/) for reference
const dataCredentials = JSON.parse(
JSON.stringify(
require("../fixtures/credentials/" + env + "-credentials.json")
)
);
Is there another way to do that line of codes above that will be accepted by eslint?
Depending on
eslint&nodeversion, there are three available options.Option #1. Disable the rule via inline comment
This one is the easiest:
Option #2. Use FileSystem module to read JSON files
Option #3. Split ESLint config
If you're using "flat" ESLint config, you can specify what rules should be disabled for NodeJS modules.