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.42k stars 131 forks source link

Error: could not find a declaration file for graphql-upload module #359

Closed gimtwi closed 1 year ago

gimtwi commented 1 year ago

I'm using graphql-upload v. 16.0.2

Here is how I'm importing graphqlUploadExpress and other files: import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";

Here is my package.json:

{
  "name": "workspace-booking-system-backend",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.ts",
  "scripts": {
    "redis": "redis-cli",
    "sv": "nodemon --exec ts-node src/index.ts",
    "build": "npx tsc",
    "watch": "tsc -w",
    "start": "ts-node src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@typegoose/typegoose": "^9.11.0",
    "apollo-server-core": "3.11.1",
    "apollo-server-express": "3.11.1",
    "bcryptjs": "2.4.3",
    "class-validator": "0.13.2",
    "connect-redis": "6.1.3",
    "cors": "2.8.5",
    "date-fns": "2.29.3",
    "dotenv": "16.0.3",
    "express": "4.18.2",
    "express-session": "1.17.3",
    "graphql": "^15.3.0",
    "graphql-upload": "16.0.2",
    "ioredis": "5.2.4",
    "mongodb": "^4.1.0",
    "mongoose": "^6.5.2",
    "mongoose-autopopulate": "^0.16.1",
    "nodemailer": "6.8.0",
    "reflect-metadata": "0.1.13",
    "type-graphql": "1.1.1",
    "uuid": "9.0.0"
  },
  "devDependencies": {
    "@types/bcryptjs": "2.4.2",
    "@types/connect-redis": "0.0.19",
    "@types/express": "4.17.14",
    "@types/express-session": "1.17.5",
    "@types/graphql-upload": "15.0.2",
    "@types/node": "18.11.9",
    "@types/nodemailer": "6.4.6",
    "@types/uuid": "8.3.4",
    "nodemon": "2.0.20",
    "ts-node": "10.9.1",
    "typescript": "4.8.4"
  },
  "exports": {
    "./GraphQLUpload.mjs": "./GraphQLUpload.mjs",
    "./graphqlUploadExpress.mjs": "./graphqlUploadExpress.mjs",
    "./graphqlUploadKoa.mjs": "./graphqlUploadKoa.mjs",
    "./package.json": "./package.json",
    "./processRequest.mjs": "./processRequest.mjs",
    "./Upload.mjs": "./Upload.mjs"
  }
}

Here is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "Node16",
    "lib": ["es2018", "esnext.asynciterable"],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "outDir": "./dist",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false
  },
  "exclude": ["node_modules"],
  "include": ["./src/**/*.ts"]
}

No matter what I do, I still get the error. I tried just declare module with and without @types/graphql-upload installed, but application crushes with the same error, although I declared module/installed @types/graphql-upload. Screenshot from 2023-01-27 14-45-50

Has anyone faced this problem? What can I try next?

jaydenseric commented 1 year ago

While there are a couple of things to try it's possible you are dealing with ts-node having poor support for ESM, .mjs and nodenext/node16 mode:

https://github.com/TypeStrong/ts-node#native-ecmascript-modules

Try type checking the project using the real TypeScript CLI instead of ts-node and see if it is able to compile ok. Perhaps using a command like this (going off memory, maybe check the CLI docs if I got this wrong):

tsc -p tsconfig.json --noEmit

If you still have the error, make sure all the documented TypeScript requirements are met:

https://github.com/jaydenseric/graphql-upload/blob/e01b5d5541760d529b06c900883c5fa7febcff00/readme.md?plain=1#L55-L59

Enable compilerOptions.allowJs; that could be your problem.

It looks like you have not configured compilerOptions.maxNodeModuleJsDepth, which can cause an error like your one.

I'm not sure, but maybe also try removing compilerOptions.skipLibCheck.

Definitely don't install @types/graphql-uploadgraphql-upload ships it's own types as TypeScript flavour JSDoc comments in the distributed .mjs modules.

jaydenseric commented 1 year ago

Closing because this isn't an actionable issue from my side, but feel free to comment if any of the suggestions above helped in your project.

devhoangkien commented 1 year ago

You can try read post Nestjs Graphql uploads single, or multiple files into a Cloudinary it might help you