Reputation: 15290
From node docs, I am trying some code from Buffer
.
When I execute this statement
const buf = Buffer.from('hello world', 'ascii');
it throws an exception: TypeError: Buffer.alloc is not a function
My node version is v5.7.1.
I don't understand why?
Here is the error screen.
Upvotes: 14
Views: 23106
Reputation: 1
I have also faced the same issue.
Just do Buffer.Buffer.alloc()
, it works fine then :)
hope it helps
Upvotes: 0
Reputation: 694
For whatever reason my alloc function was a couple objects down. Please verify your console.log(Buffer)
let Buffer = require('buffer');
console.log(Buffer)
data = Buffer.Buffer.alloc(0);
Upvotes: 0
Reputation: 536
If you don't want to restart you can just do this:
sudo apt install curl
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt install nodejs
node -v
Instructions from here: https://websiteforstudents.com/install-the-latest-node-js-and-nmp-packages-on-ubuntu-16-04-18-04-lts/
Upvotes: 0
Reputation: 197
if you can do these commands,it should be work.
step 1:
first, you can type this command sudo npm cache clean -f
step 2:
Now,you can type this command
sudo npm install -g n
step 3:
Now ,you should enter this command
sudo n 6.4.0
step 4:
finally, you should enter this command for restart the your system or reboot
shutdown -h now
Upvotes: 1
Reputation: 1715
This error occurs due to missmatch node version so please node version on my machine like this:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Upvotes: 4