Skip to content
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

Latest V15 "Cannot find module koa" #314

Closed
TurtIeSocks opened this issue May 28, 2022 · 11 comments
Closed

Latest V15 "Cannot find module koa" #314

TurtIeSocks opened this issue May 28, 2022 · 11 comments
Labels

Comments

@TurtIeSocks
Copy link

TurtIeSocks commented May 28, 2022

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:

  • TypeScript
  • Express
  • Apollo Server

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
Copy link

Same here:

import { GraphQLUpload } from 'graphql-upload'

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

@TurtIeSocks
Copy link
Author

@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
Copy link

@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
Copy link
Owner

@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

"exports": {
"./GraphQLUpload.js": "./GraphQLUpload.js",
"./graphqlUploadExpress.js": "./graphqlUploadExpress.js",
"./graphqlUploadKoa.js": "./graphqlUploadKoa.js",
"./package.json": "./package.json",
"./processRequest.js": "./processRequest.js",
"./Upload.js": "./Upload.js"
},

You can see more details about importing in this issue and comment:

#305 (comment)

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
Copy link

KillerCodeMonkey commented May 29, 2022

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
Copy link

KillerCodeMonkey commented May 29, 2022

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

@jaydenseric
Copy link
Owner

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:

"peerDependenciesMeta": {
"@types/express": {
"optional": true
},
"@types/koa": {
"optional": true
}
},

@KillerCodeMonkey
Copy link

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
Copy link
Owner

The fix has been published in v15.0.1 🚀

@TurtIeSocks
Copy link
Author

Confirmed, thanks @jaydenseric!

@gkTim
Copy link

gkTim commented Jun 9, 2022

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?

krasivyy3954 added a commit to krasivyy3954/react-graphql-upload that referenced this issue Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants