背景
node server 提供 ipfs 文件上传服务
源码
const { create, globSource } = require('ipfs-http-client');this.ipfs = create({ host: host, port: port, protocal: protocal });async addAll(files) { let addOptions = { pin: true, // wrapWithDirectory: true, timeout: 10000 }; try { let res = [] for await (const result of this.ipfs.addAll(files, addOptions)) { res.push({ path: result.path, size: result.size }) } return res } catch (error) { throw error }}
调用 addAll()
办法提醒谬误
ReferenceError: AbortController is not defined
起因
AbortController
对 node 版本有要求,要求 v16.xx.xx,所以只须要降级 node 版本即可。
降级 node
服务器零碎是 centos,能够抉择 node 版本管理工具 n
装置 n
npm install -g n
下载 node
n 10.16.0 // 指定版本下载n lts // 最新版本下载
切换 node 版本
n node/8.11.3 node/10.15.0 node/v16.8.0
查看以后版本
node -v
如果这里发现还是原来的版本,没有降级胜利有可能是本地 node 指向问题,n
装置的源文件默认装置在 /usr/local/bin
上面,先查看下以后指向
which node
如果没有指向 /usr/local/bin
,批改本地配置
vim ~/.bash_profileN_PROFIX=/usr/localPATH=$N_PROFIX/bin:$PATHexport PATH
查看以后版本
node -vv16.8.0
后果
降级完结后,重新安装依赖启动服务,再次调用 addAll
办法,调用胜利。
总结
从遇到问题到解决问题,破费工夫次要在降级 node 版本而不是定位问题。遇到这个问题不能阐明什么,毕竟问题切实太多纯靠积攒,然而在 node 生态工具的应用上还是十分欠缺破费了不少工夫,后续能够在这方面深刻一点。