Error: No "exports" main defined in graphql-upload/package.json
Error: No "exports" main defined in graphql-upload/package.json
已安装 graphql-upload,执行
import { graphqlUploadExpress } from 'graphql-upload';
并收到此错误:
错误:graphql-upload/package.json
中未定义“导出”主体
依赖关系:
"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",
节点版本:v16.10.0
graphql-upload
库没有任何主要 index.js
re-export 的所有功能。它具有针对所有特定功能的直接文件导出。它在 package.json
文件中的 exports
键下指定,如下所示:
"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"
},
因此,您需要指定一个 sub-module 路径,而不是直接从包根导入:
import graphqlUploadKoa from "graphql-upload/graphqlUploadKoa.js";
我个人放了一个 ts-ignore 来忽略错误。
// @ts-ignore
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
然后像那样导入。脏了也希望能帮到你!
所以问题出在 .default 构建设置中。
您可以删除它,但是当我们删除它时,我们发现其他模块存在问题,因此我们通过以下方式解决了这个问题:
import Upload = require('graphql-upload/Upload.js');
它看起来很脏,但它确实有效。
您可以在 GitHub 上的问题中查看有关此模块的讨论:https://github.com/jaydenseric/graphql-upload/issues/305#issuecomment-1136574019
已安装 graphql-upload,执行
import { graphqlUploadExpress } from 'graphql-upload';
并收到此错误: 错误:graphql-upload/package.json
中未定义“导出”主体依赖关系:
"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",
节点版本:v16.10.0
graphql-upload
库没有任何主要 index.js
re-export 的所有功能。它具有针对所有特定功能的直接文件导出。它在 package.json
文件中的 exports
键下指定,如下所示:
"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"
},
因此,您需要指定一个 sub-module 路径,而不是直接从包根导入:
import graphqlUploadKoa from "graphql-upload/graphqlUploadKoa.js";
我个人放了一个 ts-ignore 来忽略错误。
// @ts-ignore
import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';
// @ts-ignore
import Upload from 'graphql-upload/Upload.js';
然后像那样导入。脏了也希望能帮到你!
所以问题出在 .default 构建设置中。 您可以删除它,但是当我们删除它时,我们发现其他模块存在问题,因此我们通过以下方式解决了这个问题:
import Upload = require('graphql-upload/Upload.js');
它看起来很脏,但它确实有效。
您可以在 GitHub 上的问题中查看有关此模块的讨论:https://github.com/jaydenseric/graphql-upload/issues/305#issuecomment-1136574019