本文介绍了TypeError:Buffer.alloc不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从节点文档中,我正在尝试 Buffer 中的一些代码.

From node docs, I am trying some code from Buffer .

当我执行此语句时

const buf = Buffer.from('hello world', 'ascii');

它引发异常:TypeError: Buffer.alloc is not a function

我的节点版本是v5.7.1.

My node version is v5.7.1.

我不明白为什么?

这是错误屏幕.

推荐答案

新的Buffer API仅在v5.10.0 +中可用,因此您需要进行升级才能使用它.

The new Buffer API is only available in v5.10.0+, so you'll need to upgrade to use it.

如果要查看v5.7.1的文档,可以在此处.

If you want to view the docs for v5.7.1, you can go here.

FWIW,新的Buffer API也从v4.5.0开始在节点v4.x中可用.

FWIW the new Buffer API is also now available in node v4.x as of v4.5.0.

这篇关于TypeError:Buffer.alloc不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:05