resize-img 模块期望“buffer”为“Buffer”类型,但接收到“object”类型。记录参数 returns 缓冲区

resize-img module expected `buffer` to be of type `Buffer` but received type `object`. Logging argument returns buffer

未处理的拒绝 (TypeError):预期 bufferBuffer 类型但收到的类型为 object 推../node_modules/resize-img/index.js.module.exports

let pathi = fs.readFileSync(path.join(this.props.dir.server, "server-icon-0.png"));
console.log(pathi);

const image = await resizeImg(pathi, {
     width: 64,
     height: 64,
});

fs.writeFileSync(path.join(this.props.dir.server, "server-icon.png"), image);

日志记录 pathi returns 一个 Buffer.

Buffer(77763)

它是一个 Uint8Array 的实例,里面显然有 77k+ 个数字。

运行 此代码在不同的项目中有效。我的代码或我的项目有问题吗?

Anatoly 的帮助下找到了答案。

检查 pathi 是否真的是带有 Buffer.isBuffer(pathi)Buffer 的实例返回 false。使用 Buffer(pathi) Buffer.isBuffer(Buffer(pathi)) 构建新缓冲区后返回 true!