Closed ahmadxgani closed 1 year ago
There are a lot of old issues that would have answered this question.
import GraphQLUpload from "graphql-upload/GraphQLUpload.mjs";
import type { FileUpload } from "graphql-upload/processRequest.mjs";
Be sure to configure TypeScript according to the requirements:
https://github.com/jaydenseric/graphql-upload/tree/v16.0.2#requirements
thanks for the feedback, i have configured my typescript configuration below
{
"compilerOptions": {
"module": "NodeNext",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"maxNodeModuleJsDepth": 10
}
}
but it is still throw an error:
The error is correct; you are incorrectly attempting to import an ESM module from with a CJS module (the .ts
file).
You can learn about ESM in TypeScript and Node.js here:
I tried to add dynamic import inside @Field decorator, but it doesn't seem to support async inside the decorator, how can i fix it?
@Field(async () => (await import('graphql-upload/GraphQLUpload.mjs')).default)
image: Promise<FileUpload>;
Error: Cannot determine a GraphQL input type null for the "image". Make sure your class is decorated with an appropriate decorator.
at InputTypeFactory.create (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\@nestjs\graphql\dist\schema-builder\factories\input-type.factory.js:19:23)
at D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\@nestjs\graphql\dist\schema-builder\factories\input-type-definition.factory.js:48:52
at Array.forEach (<anonymous>)
at D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\@nestjs\graphql\dist\schema-builder\factories\input-type-definition.factory.js:46:33
at resolveObjMapThunk (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\graphql\type\definition.js:504:40)
at defineInputFieldMap (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\graphql\type\definition.js:1313:20)
at GraphQLInputObjectType.getFields (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\graphql\type\definition.js:1276:27)
at collectReferencedTypes (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\graphql\type\schema.js:395:51)
at collectReferencedTypes (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\graphql\type\schema.js:391:11)
at new GraphQLSchema (D:\GD Gani\From Github\blog\simple-blog-backend\node_modules\graphql\type\schema.js:183:7)
I tried to import GraphQLUpload
but i got this error below
package.json
how to solve this problem ?