question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`Buffer()` without a `new` keyword is going to be hard-deprecated soon

See original GitHub issue

Refs: https://github.com/nodejs/node/pull/8169, https://github.com/nodejs/node/pull/7152.

Two options here:

  • Use the new Buffer API — Buffer.alloc()/Buffer.from()/Buffer.allocUnsafe() (requires a shim for v0.10/v0.12 and older v4.x versions prior to v4.5.0).
  • Use new Buffer() for the time being — just add the new keyword everywhere. You should manually check that everything is safe in this case, see the links below for more explanation. That might be hard-deprecated at some later point.

More background:

Quick grep (you should better re-check):

browserify-13.1.0.tgz/test/bare.js:34:    ps.stdin.end('console.log(Buffer("ABC"))');
browserify-13.1.0.tgz/test/bare_shebang.js:32:    ps.stdin.end('#!/usr/bin/env node\nconsole.log(Buffer("WOO"))');
browserify-13.1.0.tgz/test/global/buffer.js:1:t.equal(Buffer('xyz').toString('base64'), 'eHl6');
browserify-13.1.0.tgz/test/global/buffer.js:2:t.equal(Buffer('eHl6', 'base64').toString(), 'xyz');
browserify-13.1.0.tgz/test/leak.js:46:    stream.push('t.equal(Buffer("eHl6", "base64").toString(), "xyz")');

The grep above only includes the lines that call Buffer() without the new keyword, if you choose to move to the new API — you should probably also replace new Buffer(…) calls.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ghostcommented, Nov 4, 2016

This really sucks. I feel like node core pulled a fast one here and created so much fucking work for everyone in the ecosystem without thinking things through very carefully.

2reactions
mscdexcommented, Nov 13, 2016

@spelunk To be fair, “pulling a fast one” would be if node core simply dropped constructor usage without any warning. The warning is there to give people time to migrate.

I honestly believe the only real solution is to fix the deprecations upstream/downstream, otherwise you’re just masking the problem and you will get bitten once the deprecation becomes a removal at some point. At that time, things will probably be even worse because you’ll be scrambling to fix actual broken dependencies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Buffer() without a new keyword is going to be hard-deprecated ...
5.0). Use new Buffer() for the time being — just add the new keyword everywhere. You should manually check that everything is safe...
Read more >
Only void function can be called with the "new" keyword
I find a way to shut the typescript compiler up, but this will give up the type check(Do it with your caution). var...
Read more >
new operator - JavaScript - MDN Web Docs - Mozilla
When a function is called with the new keyword, the function will be used as a constructor. new will do the following things:....
Read more >
The “new” keyword, in far too many languages - Medium
I've written this series of blog posts about the new keyword in many languages, as I feel this is a great common thread...
Read more >
Flux (reactor-core 3.5.1)
A Reactive Streams Publisher with rx operators that emits 0 to N elements, and then completes (successfully or with an error).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found