TypeScript,从自制软件包中导入模块时,tsconfig.json中出现错误

时间:2019-02-22 23:32:21

标签: typescript

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

$ yarn add git+ssh://git@github.com:my_gh/my-api-types.git --dev

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

import { AccountResolvers } from "my-api-types";

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.

我的 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
   }
 }

更新

当帮助文档显示“ composite”选项设置为“ false”时,问题就消失了。

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

  • rootDir设置(如果未显式设置)默认为包含tsconfig文件的目录
  • 所有实现文件必须使用include模式匹配或列在files数组中。如果违反了此约束,tsc会通知您未指定哪些文件
  • declaration必须打开

0 个答案:

没有答案
相关问题