-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript error: Cannot find module 'query.gql' #42
Comments
Sorry, been able to find a solution by using "require" instead of "import", eg: Closing this issue. |
BTW look into typescript code generation with apollo-codegen: https://github.com/apollographql/apollo-codegen |
Seems like |
I'm having the same problem by the way; I'm using graphql-loader to load .graphql files, but I have to use require() instead of import in typescript source code. |
The correct fix to this is to extend the Typescript definition, as such. // webpack.d.ts
declare module "*.gql" {
const content: any;
export default content;
}
declare module "*.graphql" {
const content: any;
export default content;
} The reason I use Line 1 in 1fd2c9d
But the correct typespec is the following one declare module "*.gql" {
import { DocumentNode } from "graphql";
const content: DocumentNode;
export default content;
}
declare module "*.graphql" {
import { DocumentNode } from "graphql";
const content: DocumentNode;
export default content;
} |
@yordis this doesn't seem to work for me. My understanding is that a I'm still getting this error, though, despite a directory that looks like this:
|
❗️SOLVED❗️Oh my god, I found the problem. @yordis's comment was almost right. Here's the problem with his code (first three lines): // webpack.d.ts
declare module "*.qql" {
const content: any; You're probably not seeing what's wrong here, so I'll make it explicit with capital letters: declare module "*.QQL" { This was either a grave typo, or in some world people name graphql files with the extension QQL. Here's the working snippet: // webpack.d.ts
declare module "*.qql" {
const content: any;
export default content;
}
declare module "*.graphql" {
const content: any;
export default content;
} @yordis if you can update your comment, please do. |
@dfee English 😢 I update the message and also improve the typespec. |
I ended up using I think this issue can be safely closed. |
Anyone know how to add: declare module "*.graphql" {
const content: string; // string or DocumentNode doesn't really matter for me
export default content;
} Into a package inside a monorepo using like Turborepo, Lerna or Nx? That could be shared and published if I want to? Like the scoped packages from @types? I know I can create a package called I would like it to be called same as my other scoped packages. |
@EloB check this, So a reusable package: https://github.com/straw-hat-team/types/blob/master/src/css-modules.ts Then import it inside a For example, /// <reference types="@straw-hat/types/dist/css-modules" />
/// <reference types="@straw-hat/types/dist/svgr-webpack" /> |
I am using typescript 2.1.4 and using graphql-tag/loader for webpack. Unfortunately I am receiving this error whenever I compile from typescript.
The text was updated successfully, but these errors were encountered: