【问题标题】:Intellij can't find tsconfig.jsonIntellij 找不到 tsconfig.json
【发布时间】:2017-11-30 19:37:52
【问题描述】:

我遇到了 Intellij 无法找到我的 tsconfig.json 文件的问题。我的文件夹结构是这样的:

/ui
  /src (all typescript files in here)
  tsconfig.json

在我的tsconfig.json 文件中,我有:

{
  "compilerOptions": {
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es7", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": false,
    "suppressImplicitAnyIndexErrors": true,
    "experimentalDecorators": true,
    "types": [
      "node",
      "webpack-env"
    ]
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest"
  ],
  "include": [
    "src/**/*"
  ]
}

Intellij 知道如何使用 command + B(转到声明)从“src”导航到我的 src 文件夹。如果我关闭 Intellij 并重新打开它并在 Typescript 中单击“全部编译”,它甚至会将所有内容编译为 Javascript。然后它报告错误Error: Cannot find parent 'tsconfig.json'。有时它仍然会编译为 Typescript,但当我单击“全部编译”时,它永远不会编译。

这是 Intellij 错误吗?好像是一个。我刚刚升级到 Intellij 2017.3,虽然我不确定我之前是否遇到过这个问题。

Typescript 版本是 2.6.2,但我在使用 2.5.3 时遇到了同样的问题。

【问题讨论】:

    标签: typescript intellij-idea tsconfig


    【解决方案1】:

    我也遇到了同样的问题。我通过在 Typescript 下的 Settings 中明确设置 tsconfig.json 的路径来解决它(有一个 Options 输入字段):

    -p ./tsconfig.json
    

    ./ 是我项目中的根目录。在你的情况下可能会有所不同,就像可能

    -p ./ui/tsconfig.json
    

    【讨论】:

    • 很高兴知道这不仅仅是我的项目有这个问题!尽管 Intellij 仍在显示用作未使用的函数...啊!
    • 感谢您的提示。我打开了这张票youtrack.jetbrains.com/issue/IDEA-184264
    猜你喜欢
    • 1970-01-01
    • 2020-10-24
    • 2023-03-28
    • 2022-08-11
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 2018-04-22
    • 1970-01-01
    相关资源
    最近更新 更多