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
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
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!
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
Just like every answer, the maintainer of the package has chosen to restrict the imports for this package. I run into the same issue and have decided to stick with version 13 moving forward.
You can use the old imports with version 13
import { graphqlUploadExpress } from 'graphql-upload';
The owner of the package just chooses to restrict importing everything from the index file, so to run the new version (> 13.0.0) you have to change the way you are importing the package:
const graphqlUploadExpress = require('graphql-upload/graphqlUploadExpress.js');
or
const GraphQLUpload = require('graphql-upload/GraphQLUpload.js');
Alternatively, you can download grade your package to version 13.0.0
Just ran into this problem. Apparently, the the new version ie ^16
,has a major update
now you need to do
const Upload = require('graphql-upload/Upload.mjs');
or
import { default as Upload } from 'graphql-upload/Upload.mjs';
Instead of .js
, all the imports needs to be from .mjs
.
Hope this helps
use version v15.0.1 for graphql-upload
import like this:
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';
https://github.com/jaydenseric/graphql-upload/issues/314#issuecomment-1140441744
https://github.com/jaydenseric/graphql-upload/releases/tag/v15.0.1
Supported runtime environments:
Node.js versions ^14.17.0 || ^16.0.0 || >= 18.0.0.
Projects must configure TypeScript to use types from the ECMAScript modules that have a // @ts-check comment:
compilerOptions.allowJs should be true.
compilerOptions.maxNodeModuleJsDepth should be reasonably large, eg 10.
compilerOptions.module should be "node16" or "nodenext".
I faced the same issue and I fixed it using an alternate package graphql-upload-minimal
Here is the old code
const {
graphqlUploadExpress, // A Koa implementation is also exported.
} = require("graphql-upload");
const { GraphQLUpload } = require("graphql-upload");
Here is the new code
const {
graphqlUploadExpress, // A Koa implementation is also exported.
} = require("graphql-upload-minimal");
const { GraphQLUpload } = require("graphql-upload-minimal");
This fixed it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.