I faced this error " 3:13 error Require statement not part of import statement @typescript-eslint/no-var-requires" while pushing repository to github
const Koa = require("koa");
I imported this in line 3
I tried to search, but I didn't find any clue.
I faced this error " 3:13 error Require statement not part of import statement @typescript-eslint/no-var-requires" while pushing repository to github
const Koa = require("koa");
I imported this in line 3
I tried to search, but I didn't find any clue.
Share Improve this question asked May 17, 2023 at 4:56 Elmond PattananElmond Pattanan 111 silver badge3 bronze badges2 Answers
Reset to default 4Option 1: With Typescript, use have to use ES6 Syntax instead of require. So to include Koa you need to write
import Koa from 'koa';
Option 2: You can disable this rule by editing .eslintrc.js
{
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
Following on from Haziks suggestion, you also have the option to turn off this eslint rule in the file you need instead of disabling the rule everywhere by adding this to the start of said file
/* eslint-disable @typescript-eslint/no-unused-vars */
or for a specific line
// eslint-disable-next-line @typescript-eslint/no-var-requires