我需要在 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 必须开启在tsconfig.json设置复合= true
引用的项目必须启用新的复合设置。
\n需要此设置来确保 TypeScript 可以快速确定在哪里找到引用项目的输出。启用复合标志会改变一些事情:
\n当此设置打开时:>>>
\n如果未显式设置,rootDir 设置默认为包含 tsconfig.json 文件的目录。
\n所有实现文件必须通过包含模式匹配或在文件数组中列出。如果违反此约束,tsc 将通知您未指定\xe2\x80\x99 哪些文件。
\n声明默认为 true
\n| 归档时间: |
|
| 查看次数: |
3473 次 |
| 最近记录: |