简体   繁体   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

hi I want to import a graphql file.嗨,我想导入一个 graphql 文件。 For this i have installed babel-plugin-import-graphql package.but for some reason i am getting error为此,我安装了 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";
                        ~~~~~~~~~~~~~~~~~~
 

how do i do the import我如何进行导入

import typeDefs from "./schema.graphql";

graphql.d.ts graphql.d.ts

declare module "*.graphql" {
  import { DocumentNode } from "graphql";

  const value: DocumentNode;
  export = value;
}

.babelrc .babelrc

{
  "plugins": ["import-graphql"]
}

full code can be viewed here完整代码可以在这里查看

将文件从 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