警告:您当前正在运行一种TypeScript版本,该版本不受@typescript-eslint/typescript-estree官方支持。

42

你好,我的终端出现了一些错误,提示我需要使用4.4.0版本,而我当前的版本是...

在我的项目中,我的当前TypeScript版本如下所示:

    "typescript": "^4.4.2",
    "typedoc": "^0.21.8",
    "react-scripts": "^3.4.4",
    "@typescript-eslint/eslint-plugin": "^4.29.3",
    "@typescript-eslint/parser": "^4.29.3",

此外,当我试图运行npm run dev命令或npx eslint .时,会显示以下错误:

    =============

   WARNING: You are currently running a version of TypeScript which is not 
   officially supported by @typescript-eslint/typescript-estree.

    You may find that it works just fine, or you may not.

   SUPPORTED TYPESCRIPT VERSIONS: >=3.3.1 <4.4.0

   YOUR TYPESCRIPT VERSION: 4.4.2

     Please only submit bug reports when using the officially supported 
    version.

    =============

我该如何解决这个问题?我在谷歌上做了很多研究,但是什么都没用。如果能得到帮助将会非常感激。

6个回答

28
我曾经也遇到过同样的警告。通过运行以下命令将 eslint 及其相关包更新到最新版本,问题得以解决:
npm i eslint@latest @typescript-eslint/parser@latest @typescript-eslint/eslint-plugin@latest --save 现在,我的 package.json 中有以下版本,不再收到警告信息。
"eslint": "^8.38.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.22.0",
"typescript": "^5.0.4"

不一定要安装最新版本,但请打开您的 package.json 文件,并确保为更新留出足够的余地(例如,将 "@typescript-eslint/eslint-plugin": "^5.25.0", 改为 "@typescript-eslint/eslint-plugin": "^5"),然后运行 npm update @typescript-eslint/eslint-plugin 等命令。 - til

14

我不会降级我的Typescript,因为这样你将会错过最新的TS功能。相反我会找到一种更新@typescript-eslint/typescript-estree的方法。

你可能没有直接安装它,而是作为另一个包@typescript-eslint/experimental-utils的依赖项,比如说@typescript-eslint/eslint-plugin。因此在你的yarn.lock / package.lock文件中找到父包并升级它,结果应该也会升级@typescript-eslint/typescript-estree


1
我遇到了同样的问题。您能否更清楚地解释一下“追踪父级包...并将其升级”是什么意思?我以前从未手动编辑过锁定文件。这是我的pnpm-lock.yaml文件:https://github.com/currenthandle/react-road-to-enterprise/blob/main/pnpm-lock.yaml - currenthandle
1
嗯,你的情况似乎与我的有些不同 - 所以我有3个包使用了不同版本的@typescript-eslint/typescript-estree,其中一个包使用了@typescript-eslint/typescript-estree@1.4.0,另外两个包使用了5.0.x4.x.x。因此,当我更新第一个包时,这导致更新了typescript-estree依赖项,警告消息消失了。 - Ivo

3
在我的情况下,问题是一个过时的eslint-config-next。确保在更新@typescript-eslint/parser@typescript-eslint/eslint-plugin之前也更新它。

1

我正在使用yarn,所以我在package.json中使用resolutions增加了@typescript-eslint/typescript-estree的版本,然后警告消失了。npm似乎可以使用overrides

package.json

  "resolutions": {
    "@typescript-eslint/typescript-estree": "^5.59.2"
  },

-1
对于未来,你只需要将typescript版本固定下来。也许最新版本的@typescript-eslint...不支持你的TS版本。

-7

尝试使用typescript版本在>=3.3.1 <4.4.0之间。 这里是可用的typescript版本列表。

更改版本后,删除node_modules文件夹和package-lock.json文件。然后执行npm install


非常感谢,我已经解决了这个问题并且添加了相关支持的TypeScript版本4.3.2,现在一切都很正常。再次感谢你的帮助。 - Barbie Doll

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接