Have installed graphql-upload, do
import { graphqlUploadExpress } from 'graphql-upload';
And getting this error: Error: No "exports" main defined in graphql-upload/package.json
Dependencies:
"graphql-upload": "^14.0.0",
"graphql": "15.8.0",
"graphql-request": "^4.2.0",
"graphql-tools": "^8.2.0",
"@nestjs/axios": "^0.0.7",
"@nestjs/common": "^8.4.1",
"@nestjs/config": "^1.1.5",
"@nestjs/core": "^8.4.1",
"@nestjs/graphql": "^9.1.2",
"@nestjs/platform-express": "^8.0.0",
The version of node: v16.10.0
I have personally put a ts-ignore for ignore errors.
// @ts-ignore
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
And imports like that. I hope it can help even if it's dirty!
graphql-upload library doesn't have any main index.js re-export for all of its functions. It has direct file exports for all the specific functionalities. It is specified in its package.json file under exports key like so:
"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"
},
So instead of directly importing from package root you need to specify a sub-module path like this:
import graphqlUploadKoa from "graphql-upload/graphqlUploadKoa.js";
Reference: package.json of graphql-upload
So the problem was in the .default build settings. You can remove it, but when we removed it we saw the problem with other modules, so we resolved this issue via this:
import Upload = require('graphql-upload/Upload.js');
It looks very dirty, but it works.
You can check conversation about this module in issues on GitHub: https://github.com/jaydenseric/graphql-upload/issues/305#issuecomment-1136574019