TypeScript,从自制包导入模块时tsconfig.json出错

aar*_*rio 8 typescript

我需要在 Node 项目之间共享一些功能,所以我在我的 Github 帐户中创建了一个私有存储库,然后将其添加到一个新项目中:

$ yarn add git+ssh://git@github.com:my_gh/my-api-types.git --dev
Run Code Online (Sandbox Code Playgroud)

我可以在node_modules/my-api-types目录中看到代码,我可以使用以下命令导入代码:

import { AccountResolvers } from "my-api-types";
Run Code Online (Sandbox Code Playgroud)

VS Code 不会发送任何错误消息,实际上 IDE 会正确显示 AccountResolvers 中的方法。但是当我想编译项目时,我得到:

ERROR in /home/manuel/customer-service/tsconfig.json
[tsl] ERROR
    TS6307: File '/home/manuel/customer-service/node_modules/my-api-types/src/features/account/account.graphql.ts' 
    is not in project file list. Projects must list all files or use an 'include' pattern.
Run Code Online (Sandbox Code Playgroud)

我的tsconfig.json的错误地址,但我在其他项目中使用相同的文件没有问题:

  {
   "compilerOptions": {
    "composite": true,
    "target": "es2016",
     "module": "commonjs",
     "moduleResolution": "node",
     "esModuleInterop": true,
     "outDir": "./dist/",
     "noImplicitAny": true,
     "skipLibCheck": true,
     "jsx": "react",
     "moduleResolution": "node",
     "noFallthroughCasesInSwitch": true,
     "forceConsistentCasingInFileNames": true,
     "noImplicitReturns": true,
     "allowSyntheticDefaultImports": true,
     "strict": true,
     "noUnusedLocals": true
   }
 }
Run Code Online (Sandbox Code Playgroud)

更新

当“Composite”设置为“FALSE”选项时,问题消失,帮助DOC说:

引用的项目必须composite启用新设置。需要此设置以确保 TypeScript 可以快速确定在哪里可以找到引用项目的输出。启用composite标志会改变一些事情:

  • rootDir设置,如果没有明确设置,默认为包含tsconfig文件的目录
  • 所有实现文件都必须与include模式匹配或列在files数组中。如果违反此约束,tsc将通知您未指定哪些文件
  • declaration 必须开启

Ahm*_*nes 2

tsconfig.json设置复合= true

\n

引用的项目必须启用新的复合设置。

\n

需要此设置来确保 TypeScript 可以快速确定在哪里找到引用项目的输出。启用复合标志会改变一些事情:

\n

当此设置打开时:>>>

\n
    \n
  • 如果未显式设置,rootDir 设置默认为包含 tsconfig.json 文件的目录。

    \n
  • \n
  • 所有实现文件必须通过包含模式匹配或在文件数组中列出。如果违反此约束,tsc 将通知您未指定\xe2\x80\x99 哪些文件。

    \n
  • \n
  • 声明默认为 true

    \n
  • \n
\n

来源

\n

  • 虽然此代码可以回答问题,但提供有关如何和/或为何解决问题的附加上下文将提高​​答案的长期价值。 (2认同)