Closed TurtIeSocks closed 2 years ago
Same here:
import { GraphQLUpload } from 'graphql-upload'
error TS2307: Cannot find module 'graphql-upload' or its corresponding type declarations.
@RemyMachado if you change your import statement to what I have in the OP and remove the external @types/graphql-upload
package, you should be able to get past that.
@TurtIeSocks Unfortunately, no.
import GraphQLUpload from 'graphql-upload/GraphQLUpload'
gives me:
Could not find a declaration file for module 'graphql-upload/GraphQLUpload'
I'm so annoyed by this library's import style.
I'm done. I removed the error with // @ts-ignore
@TurtIeSocks thanks for the thanks about this package, it's appreciated.
Look in node_modules/graphql-upload/
: There is no file called GraphQLUpload
. So importing it can not be expected to magically work. The file is called GraphQLUpload.js
.
You need to do this (with the .js
in the path):
import GraphQLUpload from "graphql-upload/GraphQLUpload.js";
The readme documents what modules are publicly exported, what format they are in, what there file names are, and links to the package.json
file so you can see the package exports yourself:
You can see more details about importing in this issue and comment:
https://github.com/jaydenseric/graphql-upload/issues/305#issuecomment-1140352014
Hopefully with the correct imports the TypeScript error regarding graphqlUploadKoa.js
will go away. There is a chance though it's a seperate issue to resolve, and there are a few things to consider in that case.
hey there. got the same problem. i think it is because you are linking all type defs in the preocessRequest.js
/** @typedef {import("./GraphQLUpload.js")} GraphQLUpload */
/** @typedef {import("./graphqlUploadExpress.js")} graphqlUploadExpress */
/** @typedef {import("./graphqlUploadKoa.js")} graphqlUploadKoa */
but if you are not using koa... or vice versa express you will get the error.
So i installed koa... but then i get:
node_modules/graphql-upload/graphqlUploadKoa.js:45:28 - error TS2694: Namespace 'Application' has no exported member 'Context'.
so you need to add @types/koa to your dependencies as well. Then its working
Thanks for finding the problem! Installing koa
might not help as much as installing @types/koa
. I'll remove that type import from processRequest
and hopefully that will fix the issue.
The intention was that you should not need the Koa types installed if you are using Express, and vica versa. That's why those types are optional peer dependencies:
PS: you are write typings are enough. i do not know how exactly the typings with js works, so i thought it really imports source to extract the typings from the package. But nice that there is no overhead recarding in the production build size because only typings are needed during build time. so i get this going for me :D
The fix has been published in v15.0.1 🚀
Confirmed, thanks @jaydenseric!
Would be great to add a section to the readme on how to import it in typescript, since this import style is not so common. So users don't need to search how to fix it.
I won't be able to create a PR in the next three weeks but after that I can do it if you want. Do you have a preferred place where to put it into the readme?
I'm upgrading from V13, followed the guide that demonstrated how to update the import paths. (I would recommend linking the GH issue in the patch notes maybe?)
Info:
Using the following:
Receiving the error:
I see the following in
graphqlUploadKoa.js
, if it helps:Any recommendations?
Thanks for the package!