How can I fix error TS5023 throwed by adding "allowImportingTsExtensions" in tsconfig.json file?

huangapple go评论85阅读模式
英文:

How can I fix error TS5023 throwed by adding "allowImportingTsExtensions" in tsconfig.json file?

问题

Here is the translation of the provided text:

在构建或运行我的React项目时,我遇到了以下错误:

> 无法解析tsconfig.json。请确保它包含语法正确的JSON。
> 详细信息:错误TS5023:未知的编译器选项'allowImportingTsExtensions'。

我对错误可能原因进行了一些研究,但这些都无法帮助我:

为了背景信息:

  • 我确保在我的tsconfig.json文件中包含了选项**"noEmit": true**;
  • 我尝试添加了另一个选项,现在我记不清了;
  • 排除**"allowImportingTsExtensions"**甚至都不可能,因为我在项目中需要它。

以下代码片段表示我的tsconfig.json文件:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "strictNullChecks": false,
    "allowImportingTsExtensions": true
  },
  "include": [
    "src"
  ]
}

有人可以帮我修复这个错误吗?

英文:

While building or running my React project I encounter the following error:

> Could not parse tsconfig.json. Please make sure it contains syntactically correct JSON.
> Details: error TS5023: Unknown compiler option 'allowImportingTsExtensions'.

I did some research on the possible cause of the error but those couldn't help me:

For context:

  • I made sure of including in my tsconfig.json file the option "noEmit": true;
  • I've tried to add another option that now I can't remember;
  • Excluding "allowImportingTsExtensions" isn't even possible because I need it in the project.

The following snippet represents my tsconfig.json file:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "strictNullChecks": false,
    "allowImportingTsExtensions": true
  },
  "include": [
    "src"
  ]
}

Can anybody help me fix this error?

答案1

得分: 0

你可能会在控制台中运行 tsc 命令(以及构建脚本中)的版本与 VSCode 中的版本不一致时遇到此错误。

要修复它,请移除全局 TypeScript:

npm uninstall -g typescript

然后重新安装它:

npm install -g typescript
英文:

You might get this error when tsc command in the console (and in the build script) does not have the same version as what you have in VSCode.

to fix it remove the global TypeScript :

npm uninstall -g typescript 

the nand reinstall it again :

npm install -g typescript

huangapple
  • 本文由 发表于 2023年5月13日 17:06:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241919.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定