相关疑难解决方法(0)

错误 TS6059:文件不在“rootDir”下..“rootDir”应包含所有源文件

我收到了这个相当无意义的 tsc 转译错误:

错误 TS6059:文件“/Users/alex/codes/interos/teros-cli/src/logging.ts”不在“rootDir”“/Users/alex/codes/teros/notifier-server/src”下。'rootDir' 应包含所有源文件。

我的 PWD/Users/alex/codes/teros/notifier-server和 tsconfig.json 文件/Users/alex/codes/teros/notifier-server/tsconfig.json是:

{
  "compilerOptions": {
    "outDir": "dist",
    "allowJs": false,
    "pretty": true,
    "resolveJsonModule": true,
    "sourceMap": false,
    "skipLibCheck": true,
    "rootDir": "src",
    "declaration": false,
    "baseUrl": ".",
    "target": "es2018",
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "allowUnreachableCode": true,
    "lib": [
      "es2017",
      "es2018"
    ]
  },
  "compileOnSave": false,
  "include": [
    "src"
  ]
}
Run Code Online (Sandbox Code Playgroud)

这似乎是一个bug..since TEROS-CLI dir是PWD外,通过单独的tsconfig.json文件管理。

我什至将此字段更改为:

  "include": [
    "/Users/alex/codes/teros/notifier-server/src"
  ],
  "exclude": [
    "/Users/alex/codes/teros/teros-cli"
  ]
Run Code Online (Sandbox Code Playgroud)

仍然得到同样的错误。

typescript tsc

29
推荐指数
2
解决办法
3万
查看次数

为了将 main 与测试编译分开,需要设置哪些正确的 typescript 编译器 (tsc) 选项?

注意:如果您想查看完整的项目,此问题的公共 git 存储库位于https://github.com/matthewadams/ts-test 。

我正在尝试将项目中的主源编译与测试源编译分开。这是源目录结构:

src
  main
    ...typescript source files and possibly child directories with sources
  test
    unit
      ...unit test sources
    integration
      ...integration test sources
Run Code Online (Sandbox Code Playgroud)

我的目标将主要源代码lib/main编译到.lib/test

我试图将主编译和测试编译通用的所有编译器选项放入 中tsconfig.json,然后使用命令行参数来tsc提供特定于每个编译的选项。这是我目前的tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "alwaysStrict": true,
    "diagnostics": true,
    "disableSizeLimit": true,
    "esModuleInterop": true,
    "extendedDiagnostics": true,
    "forceConsistentCasingInFileNames": true,
    "inlineSourceMap": true,
    "inlineSources": true,
    "listEmittedFiles": true,
    "listFiles": true,
    "module": "commonjs",
    "pretty": true,
    "target": "es2015"
  }
}
Run Code Online (Sandbox Code Playgroud)

该节的一个片段package.json scripts如下(我拒绝 Gulp、Grunt 等,因为其复杂性,故意牺牲了可移植性): …

typescript tsc

6
推荐指数
1
解决办法
6402
查看次数

当测试/** 未包含在 tsconfig 中时,Vscode TS 语言功能不可用

我希望我的打字稿测试在test文件夹与src. 我不希望在构建打字稿项目时转换测试。

我的打字稿节点项目的结构如下:

.    
??? server
?   ? 
?   ?    
?   ??? src
?   ?   ?
?   ?   ??? app.ts
?   ??? test
?   ?   ?
?   ?   ??? app.test.ts
?   ??? node_modules/
?   ??? package-lock.json
?   ??? package.json
?   ??? tslint.json
?   ??? tsconfig.json
??? front_end/
??? README.md
Run Code Online (Sandbox Code Playgroud)

使用我的 tsconfig:

{
  "compilerOptions": {
    "baseUrl": ".",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "dist",
    "sourceMap": true,
    "strict": true,
    "target": "ESNext",
    "paths": {
      "*": ["node_modules/*"]
    }
  },
  "include": ["src/**/*"] …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs visual-studio-code ts-jest

4
推荐指数
1
解决办法
1298
查看次数

标签 统计

typescript ×3

tsc ×2

jestjs ×1

ts-jest ×1

visual-studio-code ×1