jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Latest V15 "Cannot find module koa" #314

Closed TurtIeSocks closed 2 years ago

TurtIeSocks commented 2 years ago

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:

import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress'
import GraphQLUpload from 'graphql-upload/GraphQLUpload'
import type { FileUpload } from 'graphql-upload/processRequest'

Receiving the error:

../../../node_modules/graphql-upload/graphqlUploadKoa.js(45,21): error TS2307: Cannot find module 'koa' or its corresponding type declarations.

I see the following in graphqlUploadKoa.js, if it helps:

Screen Shot 2022-05-28 at 11 46 47 AM

Any recommendations?

Thanks for the package!

RemyMachado commented 2 years ago

Same here:

import { GraphQLUpload } from 'graphql-upload'

error TS2307: Cannot find module 'graphql-upload' or its corresponding type declarations.

TurtIeSocks commented 2 years ago

@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.

RemyMachado commented 2 years ago

@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

jaydenseric commented 2 years ago

@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:

Screen Shot 2022-05-29 at 8 12 11 am

https://github.com/jaydenseric/graphql-upload/blob/cd9e4f1c5d7cdf66173973a3637192b11c30796c/package.json#L39-L46

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.

KillerCodeMonkey commented 2 years ago

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'.

KillerCodeMonkey commented 2 years ago

so you need to add @types/koa to your dependencies as well. Then its working

jaydenseric commented 2 years ago

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:

https://github.com/jaydenseric/graphql-upload/blob/cd9e4f1c5d7cdf66173973a3637192b11c30796c/package.json#L55-L62

KillerCodeMonkey commented 2 years ago

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

jaydenseric commented 2 years ago

The fix has been published in v15.0.1 🚀

TurtIeSocks commented 2 years ago

Confirmed, thanks @jaydenseric!

gkTim commented 2 years ago

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?