简体   繁体   English

错误:在 graphql-upload/package.json 中没有定义主要的“导出”

[英]Error: No "exports" main defined in graphql-upload/package.json

Have installed graphql-upload, do已经安装了 graphql-upload,做

import { graphqlUploadExpress } from 'graphql-upload';

And getting this error: Error: No "exports" main defined in graphql-upload/package.json并收到此错误:错误: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节点版本:v16.10.0

graphql-upload library doesn't have any main index.js re-export for all of its functions. graphql-upload库的所有功能都没有任何主要的index.js重新导出。 It has direct file exports for all the specific functionalities.它具有所有特定功能的直接文件导出。 It is specified in its package.json file under exports key like so:它在exports键下的package.json文件中指定,如下所示:

"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参考: graphql-uploadpackage.json

I have personally put a ts-ignore for ignore errors.我个人为忽略错误设置了一个 ts-ignore。

// @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.所以问题出在 .default 构建设置中。 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您可以在 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.就像每个答案一样,package 的维护者选择限制此 package 的导入。 I run into the same issue and have decided to stick with version 13 moving forward.我遇到了同样的问题,并决定继续使用第 13 版。

You can use the old imports with version 13您可以使用版本 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:包的所有者只是选择限制从索引文件中导入所有内容,因此要运行新版本(> 13.0.0),您必须更改导入包的方式:

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或者,您可以将您的包下载到版本 13.0.0

Just ran into this problem.刚遇到这个问题。 Apparently, the the new version ie ^16 ,has a major update显然,新版本ie ^16有一个重大更新

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 .而不是.js ,所有导入都需要来自.mjs

Hope this helps希望这可以帮助

use version v15.0.1 for graphql-upload使用 v15.0.1 版本进行 graphql-upload

import like this:像这样导入:

import GraphQLUpload from 'graphql-upload/GraphQLUpload.js';从'graphql-upload/GraphQLUpload.js'导入GraphQLUpload;

import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.js';从'graphql-upload/graphqlUploadExpress.js'导入graphqlUploadExpress;

https://github.com/jaydenseric/graphql-upload/issues/314#issuecomment-1140441744 https://github.com/jaydenseric/graphql-upload/issues/314#issuecomment-1140441744

https://github.com/jaydenseric/graphql-upload/releases/tag/v15.0.1 https://github.com/jaydenseric/graphql-upload/releases/tag/v15.0.1

Supported runtime environments:支持的运行时环境:

Node.js versions ^14.17.0 || Node.js 版本^14.17.0 || ^16.0.0 || ^16.0.0 || >= 18.0.0. >= 18.0.0。

  • Projects must configure TypeScript to use types from the ECMAScript modules that have a // @ts-check comment:项目必须配置 TypeScript 以使用 ECMAScript 模块中具有 // @ts-check 注释的类型:

  • compilerOptions.allowJs should be true. compilerOptions.allowJs 应该是真的。

  • compilerOptions.maxNodeModuleJsDepth should be reasonably large, eg 10. compilerOptions.maxNodeModuleJsDepth 应该相当大,例如 10。

  • compilerOptions.module should be "node16" or "nodenext". compilerOptions.module 应该是“node16”或“nodenext”。

https://www.npmjs.com/package/graphql-upload https://www.npmjs.com/package/graphql-upload

I faced the same issue and I fixed it using an alternate package graphql-upload-minimal我遇到了同样的问题,我使用备用 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.这修复了它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在使用 Graphql-upload [ERR_PACKAGE_PATH_NOT_EXPORTED] 上传图像时遇到问题:没有定义“出口”主要 - I am facing issue while uploading image using Graphql-upload [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:package.json 中没有定义“exports”main - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json 错误:在 /app/node_modules/chart.js/package.json 中没有使用 nextjs 和 chartjs 定义“导出”主要内容 - Error: No "exports" main defined in /app/node_modules/chart.js/package.json with nextjs and chartjs 如何解决包子路径 './package.json' is not defined by "exports" 错误 - How to resolve Package subpath './package.json' is not defined by "exports" error `main` 和 `module` 与 package.json 中的 `exports` 有什么区别? - What is the difference between `main` and `module` vs `exports` in package.json? 错误 [ERR_PACKAGE_PATH_NOT_EXPORTED]:@babel/helper-compilation-targets/package.json 中没有解决“导出”主要问题 - Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main resolved in@babel/helper-compilation-targets/package.json 如何从 package.json 有条件地导出 - How to conditional exports from package.json 如何使用“exports”键正确暴露 package.json 中的子路径? - How to properly expose subpaths in package.json using the ”exports” key? 清理 package.json "main" 以与 require 一起使用 - Cleaning package.json "main" for use with require 如何使用package.json中的'main'参数? - How to use the 'main' parameter in package.json?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM