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

Cannot find module 'graphql-upload' or its corresponding type declarations #319

Closed kaihaase closed 2 years ago

kaihaase commented 2 years ago

Since version 14.0.0 the error message "Cannot find module 'graphql-upload' or its corresponding type declarations" occurs in my TypeScript Project (https://github.com/lenneTech/nest-server). With version 13.0.0 everything runs without problems. Do I need to install additional packages or change anything in the TypeScript configuration?

jaydenseric commented 2 years ago

These changes are documented in the changelog and and GitHub release descriptions, and are discussed in multiple past issues, but here is what you need to do to get going:

https://github.com/lenneTech/nest-server/blob/c95c6c243b45af462947102b0f66200ea6b1d487/src/server/modules/file/file.resolver.ts#L3

- import { FileUpload, GraphQLUpload } from 'graphql-upload';
+ import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
+ import type { FileUpload } from 'graphql-upload/processRequest.js';

https://github.com/lenneTech/nest-server/blob/c95c6c243b45af462947102b0f66200ea6b1d487/src/core.module.ts#L7

- import { graphqlUploadExpress } from 'graphql-upload';
+ import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';

Make sure your TypeScript config has:

{
  "compilerOptions": {
    "allowJs": true,
    "maxNodeModuleJsDepth": 10,
    "module": "nodenext"
  }
}

Hope that helps :)

kaihaase commented 2 years ago

@jaydenseric Thank you very much for your quick support. I have left the TypeScript configuration module in the project on commonjs, because otherwise there are problems with other packages. Your hints about the imports helped me a lot though.

xerstom commented 1 year ago

Hi @jaydenseric ! Is there a way to make it work without having to use "module": "nodenext" ?

jaydenseric commented 1 year ago

@xerstom if you are importing modern ESM packages in a Node.js project, it's expected and reasonable that you have to configure TypeScript to resolve imports the modern Node.js way. You question is more a general usage/config question about TypeScript that is better asked in a TypeScript community space.

You might be able to use "module": "node16" if your project is not using top level await. You also might be able to do something different with module if you set moduleResolution to node16 or nodenext, but I'm not sure it's a good idea or will work.

lukmagg commented 1 month ago

I still have the error

import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';

Cannot find module 'graphql-upload/GraphQLUpload.js' or its corresponding type declarations.

My tsconfig.json { "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "esModuleInterop": true, "target": "es2017", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "incremental": true, "skipLibCheck": true, "strictNullChecks": false, "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "typeRoots": ["./src/typings", "node_modules/@types"] },

"exclude": ["packages", "dist", "node_modules"]

}