javascript - 3:13 error Require statement not part of import statement @typescript-eslintno-var-requires - Stack Overflow

I faced this error " 3:13errorRequire statement not part of import statement@typescript-esli

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

Option 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401448a4626121.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信