【发布时间】:2021-10-15 21:39:42
【问题描述】:
我正在尝试在使用 webpack 构建的 typescript express 应用程序 (graphql api) 中使用 graphql-upload。当我使用 ts-node 运行时,我的应用程序运行良好。但是当我使用 webpack 编译然后运行时,当我尝试上传文件时遇到一个奇怪的错误。
我的设置
- Typescript 应用程序
- Apollo 服务器/Typegraphql
- 使用 webpack 构建
我的代码
(精简到要领)
https://github.com/ziggy6792/graphql-file-uploads
我的问题
当我使用 ts-node yarn start:ts:node 运行然后运行 yarn test 时,图片上传没问题
然后我用 webpack 构建 yarn start 然后运行 yarn test 我得到以下错误
/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:56105
if (!isObject(operations) && !Array.isArray(operations))
^
TypeError: isObject is not a function
at Busboy.<anonymous> (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:56105:18)
at Busboy.emit (node:events:378:20)
at Busboy.module.exports../node_modules/busboy/lib/main.js.Busboy.emit (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:32204:33)
at PartStream.onEnd (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:32528:15)
at PartStream.emit (node:events:390:22)
at Dicer.onPart (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:32386:13)
at Dicer.emit (node:events:378:20)
at Dicer.module.exports../node_modules/dicer/lib/Dicer.js.Dicer.emit (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:45439:35)
at Dicer.module.exports../node_modules/dicer/lib/Dicer.js.Dicer._oninfo (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:45540:12)
at SBMH.<anonymous> (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:45486:10)
[nodemon] app crashed - waiting for file changes before starting...
我的解决方法
我不确定这是否真的与graphql-upload 或webpack 或其他问题有关。我还注意到我的问题看起来与 issue 类似,但我真的不明白是否有任何解决方案可以解决这个问题,以及它是否确实是我面临的同一个问题。
我尝试升级 webpack(分支 upgraded-packages),但这使问题变得更糟,因为我在启动服务器时遇到了这个问题
TypeError: Cannot read property 'graphql' of undefined
at getPeerDependencyGraphQLRequirement (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:104216:44)
at Object.ensureInstalledCorrectGraphQLPackage (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:104221:32)
at Function.checkForErrors (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103346:27)
at Function.generateFromMetadataSync (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103325:14)
at Function.generateFromMetadata (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103315:29)
at Object.buildSchema (/Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:103940:61)
at /Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:99831:41
at Generator.next (<anonymous>)
at /Users/sive/Documents/workspace/graphql-file-uploads/dist/index.js:99819:71
at new Promise (<anonymous>)
任何帮助将不胜感激。
【问题讨论】:
-
您捆绑服务器端应用程序是否有特殊原因?您想在无服务器环境中运行吗? Webpack 通常用于创建浏览器包。让它在节点上工作可能需要一些特殊的配置。
标签: node.js typescript webpack graphql