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

No "exports" main defined "\node_modules\graphql-upload\package.json" #333

Closed nekmart closed 1 year ago

nekmart commented 1 year ago

Hello, I am building a nestjs project with typescript and graphql. I want to use graphql-upload in my project.

I install two package-

  1. graphql-upload
  2. @types/graphql-upload

After installing this packages. I import it-

import { GraphQLUpload, FileUpload } from "graphql-upload";

And my Mutation-

@Mutation(() => SuccessInfo, { name: "addBrand" })
@Roles(Role.MODERATOR, Role.ADMIN)
@UseGuards(AuthGuard, RolesGuard)
add(
    @Args("brandInput") brandInput: BrandInput,
    @Args('file', { type: () => GraphQLUpload }) file: FileUpload,
) {
    return this.brandService.add(brandInput);
}

Here I am getting this error- Screenshot 2022-08-25 225447

I see this issue alreay- https://github.com/jaydenseric/graphql-upload/issues/305

From this issue I am trying to use-

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

But here I am getting typescript type declaration error like this image- Screenshot (5)

How can I solve this issue.

jaydenseric commented 1 year ago

In the readme exports section:

https://github.com/jaydenseric/graphql-upload#exports

Screen Shot 2022-08-26 at 8 01 48 am

You can see the module is documented as GraphQLUpload.mjs.

If you just look at the modules that are published:

https://unpkg.com/browse/graphql-upload@16.0.1/

Screen Shot 2022-08-26 at 8 03 01 am

You can see the module really is called GraphQLUpload.mjs.

So why are you attempting this, with .js instead of the correct .mjs?

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

Even if you were importing correctly, it seems Nest.js doesn't support importing standard JavaScript modules anyway so you will probably run into that soon, see https://github.com/jaydenseric/graphql-upload/issues/332#issuecomment-1223003793 . If you do run into that issue, please raise it with Nest.js not here.