警告:找不到父tsconfig.json

时间:2016-12-10 04:44:30

标签: typescript intellij-idea webstorm tsconfig

我想修正警告:

  

警告:找不到父tsconfig.json

Errors的TypeScript IntelliJ IDEA 2016.3标签中。我的TypeScript代码位于src目录中,而我的TypeScript输出将按预期转到lib,而src文件夹未添加到lib

我在其他项目中使用lib文件夹,它似乎按预期工作。所以这似乎不是一个大问题,但我偶尔会遇到TSLint的问题,它有时似乎没有拿起.tsx文件是JSX并且lint错误并且似乎偶尔会将其视为正常.ts个文件。最终它似乎弄明白了。我想知道这是否相关,因为我的TSLint设置被配置为使用tsconfig.json

我之前在.js文件夹中的.ts文件旁边有src个已编译文件,但最近我修改了tsconfig.json

文件如下:

tsconfig.json
src/index.ts
lib/index.js
lib/index.d.ts

我已升级到TypeScript 2.1.4,但是在2.0.10中看到它。

我的tsconfig.json文件:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "jsx": "react",
    "allowJs": false,
    "isolatedModules": false,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": true,
    "noImplicitAny": false,
    "noImplicitUseStrict": true,
    "noEmitHelpers": false,
    "removeComments": true,
    "noLib": false,
    "sourceMap": true,
    "inlineSources": true,
    "preserveConstEnums": true,
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "rootDir": "./src",
    "outDir": "./lib"
  },
  "include": [
    "./src/**/*"
  ],
  "compileOnSave": true,
  "atom": {
    "rewriteTsconfig": false
  }
}

4 个答案:

答案 0 :(得分:17)

尝试在文件include中设置tsconfig.json部分,如下图所示 (请注意,我的项目的根文件夹是 frontend ,我的include部分是 frontend/**/* )< / em>的。

当然,您不需要将项目的根文件夹重命名为frontend
只有命名应该匹配。

保存tsconfig.json并打开.ts.tsx文件后,它应立即生效。如果它没有尝试重新启动WebStorm/IDEA

在测试此解决方案之前,不要忘记清除error控制台。它可能会缓存以前的消息。

P / S: 我使用WebStorm 2016.3.1

enter image description here

如果您将webpackts-loader一起使用,则上述解决方案会导致您的构建失败。如果是这种情况,请考虑采用这种方法。

enter image description here

答案 1 :(得分:9)

问题特定于正在使用的TypeScript版本(2.1.x);它已在2016.3. 2 EAP

中修复

注意:此答案涉及IDE(WebStorm,PHPStorm,IDEA)版本2016.3特有的问题:它与TypeScript 2.1.x无法正常工作,显示错误警告。 如果您在其他IDE版本中看到类似的消息(Cannot find parent tsconfig.json),则可能是您的配置存在问题:如果当前编辑的.ts文件未包含在任何tsconfig.json中,则会显示此类消息。

答案 2 :(得分:4)

上述解决方案都不适用于我,但我偶然发现了tsconfig更改。似乎IDE正在使用tsc

的不同规则

这不起作用

"include": ["./typings", "./src", "./test"],

这确实有用

"include": ["./typings/**/*", "./src/**/*", "./test/**/*"],

答案 3 :(得分:1)

尝试将“版本号”设置为tsconfig.json文件。

{
    "version": "2.1.4",
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "jsx": "react",
        "allowJs": false,
        "isolatedModules": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": true,
        "noImplicitAny": false,
        "noImplicitUseStrict": true,
        "noEmitHelpers": false,
        "removeComments": true,
        "noLib": false,
        "sourceMap": true,
        "inlineSources": true,
        "preserveConstEnums": true,
        "allowSyntheticDefaultImports": true,
        "suppressImplicitAnyIndexErrors": true,
        "rootDir": "./src",
        "outDir": "./lib"
    },
    "include": [
        "./src/**/*"
    ],
    "compileOnSave": true,
    "atom": {
        "rewriteTsconfig": false
    }
}