![](/img/trans.png)
[英]error TS2307: Cannot find module or its corresponding type declarations. on Github Actions
[英]src/index.ts:12:22 - error TS2307: Cannot find module './schema.graphql' or its corresponding type declarations
嗨,我想導入一個 graphql 文件。 為此,我安裝了 babel-plugin-import-graphql 包。但由於某種原因我收到錯誤
\node_modules\ts-node\src\index.ts:750
return new TSError(diagnosticText, diagnosticCodes);
^
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:12:22 - error TS2307: Cannot find module './schema.graphql' or its corresponding type declarations.
12 import typeDefs from "./schema.graphql";
~~~~~~~~~~~~~~~~~~
我如何進行導入
import typeDefs from "./schema.graphql";
graphql.d.ts
declare module "*.graphql" {
import { DocumentNode } from "graphql";
const value: DocumentNode;
export = value;
}
.babelrc
{
"plugins": ["import-graphql"]
}
完整代碼可以在這里查看
將文件從
重命名為src/@types/graphql.d.ts
src/@types/index.d.ts
,保持內容不變,然后重新啟動 TS 服務器(或者只是重新加載 IDE)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.