最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论