尝试使用包裹上的超级代理上传文件时,.on 不是函数错误
.on is not a function error when trying to upload file with superagent on parcel
使用 superagent 进行设置
this.acceptContentType = "application/json";
req = Request.post(absoluteUrl)
.timeout(config.runtime.apiTimeoutMs)
.set('Accept', this.acceptContentType);
req.attach('files', file, file.name);
当 运行 这时,我收到一条错误消息,指出 .on 不是一个函数。做了一些研究,它似乎与 FormData() 对象有关。出于某种原因,superagent 向我的客户公开了节点内部结构。这在使用 Webpack 时效果很好,但在移植到 Parcel 后,它就坏了。任何指针将不胜感激。
根据 Superagent、Webpack 和 Browserify 的文档"knows" 获取客户端版本。 Parcel 选择了 Node 实现。为了强制执行此操作,我更改了:
import Request from 'superagent';
至
import Request from 'superagent/lib/client';
这似乎解决了问题。
使用 superagent 进行设置
this.acceptContentType = "application/json";
req = Request.post(absoluteUrl)
.timeout(config.runtime.apiTimeoutMs)
.set('Accept', this.acceptContentType);
req.attach('files', file, file.name);
当 运行 这时,我收到一条错误消息,指出 .on 不是一个函数。做了一些研究,它似乎与 FormData() 对象有关。出于某种原因,superagent 向我的客户公开了节点内部结构。这在使用 Webpack 时效果很好,但在移植到 Parcel 后,它就坏了。任何指针将不胜感激。
根据 Superagent、Webpack 和 Browserify 的文档"knows" 获取客户端版本。 Parcel 选择了 Node 实现。为了强制执行此操作,我更改了:
import Request from 'superagent';
至
import Request from 'superagent/lib/client';
这似乎解决了问题。