簡體   English   中英

src/index.ts:12:22 - 錯誤 TS2307:找不到模塊“./schema.graphql”或其相應的類型聲明

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM