yarn icon indicating copy to clipboard operation
yarn copied to clipboard

Replace use of deprecated/unsafe new Buffer constructor

Open ghost opened this issue 8 years ago • 84 comments

What is the current behavior?

yarn uses deprecated new Buffer() constructor and causes deprecation warnings when run with NODE_PENDING_DEPRECATION=1.

$ ag '\bBuffer\('
src/registries/npm-registry.js
340:        const pw = new Buffer(String(password), 'base64').toString();
341:        return 'Basic ' + new Buffer(String(username) + ':' + pw).toString('base64');

src/util/fs.js
835:const cr = new Buffer('\r', 'utf8')[0];
836:const lf = new Buffer('\n', 'utf8')[0];

What is the expected behavior?

yarn should not use deprecated/unsafe Buffer constructor. According to the deprecation warning new Buffer() should be replaced with one of Buffer.alloc(), Buffer.allocUnsafe() or Buffer.from(); the safe-buffer package is another option.

Please mention your node.js, yarn and operating system version.

$ node -v
v8.9.4

$ yarn -v
1.5.1

$ uname -a
Linux 4.15.6-300.fc27.x86_64 #1 SMP Mon Feb 26 18:43:03 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

ghost avatar Mar 07 '18 17:03 ghost

Getting this same warning on macOS. I believe #5704 is a duplicate of this.

malonehedges avatar Apr 24 '18 21:04 malonehedges

As a workaround for now, I've created a ~/bin/node script that comes before (Homebrew-installed) /usr/local/bin/node in my $PATH:

#!/bin/bash

/usr/local/bin/node --no-deprecation "$@"

felixrabe avatar Apr 26 '18 11:04 felixrabe

FYI: Just went through yarn's dependencies and there are two which still call new Buffer():

  • tar-stream (fixed, but we still depend on an older version)
  • v8-compile-cache (not fixed)

We will likely need to update those.

marvinhagemeister avatar Apr 28 '18 09:04 marvinhagemeister

@martinstuecklschwaiger when is the fix done???

jjhesk avatar Apr 28 '18 18:04 jjhesk

@marvinhagemeister v8-compile-cache just released 2.0.0 version, which fixed the bug. Hope we can soon update to new version.

fengerzh avatar May 05 '18 01:05 fengerzh

@fengerzh @imsnif already committed the new version to master https://github.com/yarnpkg/yarn/commit/546a1576edbf701021ce65e3dd8daff267083f52 🎉

marvinhagemeister avatar May 07 '18 14:05 marvinhagemeister

When do you plan on releasing a new version with this fix? I couldn't find any info on how you deal with releases.

I see the high-priority label was used on this issue, doesn't that also mean that you want to push the fix ASAP? Not only fixing it ASAP.

EDIT: Didn't mean to sound pushy or demanding in any way, I'm just curious how you approach these high-priority issues. The reason I asked was because it's annoying to get a warning about this for every new shell instance I start.

simeg avatar May 14 '18 09:05 simeg

This warning started popping up after I've upgraded from node v0.9.x to v0.10.1

piotr-cz avatar May 14 '18 10:05 piotr-cz

@piotr-cz you mean v10.1, 0.10 is pretty ancient.

oshalygin avatar May 15 '18 04:05 oshalygin

Thanks, I meant that the warning started popping up after upgrade from v9.x to v10.1.0

piotr-cz avatar May 15 '18 09:05 piotr-cz

Still getting this warning with yarn 1.6.0

yarn install v1.6.0
(node:22339) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security 
and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or 
Buffer.from() methods instead.

My node.js, yarn and operating system version

node -v
v10.1.0

yarn -v
1.6.0

uname -a
Darwin *****.local 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; 
root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64

Gurenax avatar May 18 '18 11:05 Gurenax

Any progress here? We would really like to use node 10 within our project without any workaround 🔥

intensr avatar May 22 '18 11:05 intensr

It's just a warning. Why would it prevent you from using it?

teohhanhui avatar May 22 '18 11:05 teohhanhui

Same issue here and it causes my Roots Sage theme not to compile failing it to deploy. See also https://discourse.roots.io/t/buffer-deprecated-yarn-warning/12525

jasperf avatar May 22 '18 13:05 jasperf

@teohhanhui Long-lived warnings are problematic because they obscure other, more useful warnings: It would be unreasonable to expect developers to look through all warnings on every build, and mentally discount only the "acceptable" ones. It's therefore common (and entirely reasonable) to treat all warnings as errors. This isn't a complaint about yarn, which is great; but the phrase "It's just a warning" raises loud mental alarm bells.

jeffs avatar May 22 '18 13:05 jeffs

There are large, extremely prosperous software/etc firms, brand names we all know, who have companywide rules like: treat warnings as errors or delete them, but never spend human labor looking through warning lists routinely. For the reason mentioned above.

This not to say this is perfect advice replies everywhere, but it is not uncommon and pretty well demonstrated as workable and valuable.

kylecordes avatar May 22 '18 16:05 kylecordes

If you're going to treat all warnings as errors, wouldn't you have a way to ignore / whitelist warnings? But anyway, I don't see how it's yarn's fault that you choose to do that. yarn is not broken in this case.

teohhanhui avatar May 22 '18 18:05 teohhanhui

Sorry to do this but I have to lock this issue since people don't seem to be reading earlier comments. Here's the summary:

  • This issue has not been resolved yet (as of Yarn 1.6.0)
  • Yes, we as the yarn team are aware and are working hard to fix this and release a new version. You can follow #5769 to see the progress (please, please do not use that PR as another discussion forum for this)
  • We have discovered an issue regarding symlinks on Windows when using Yarn on Node 10 which may cause installs to stall with an infinite recursion. This issue is also being addressed in #5769

I apologize on behalf of the whole Yarn team for the issue and the delay.

BYK avatar May 22 '18 19:05 BYK

Update: the above-mentioned PR is now merged. We'll release a new version as soon as possible.

BYK avatar May 23 '18 10:05 BYK

Version 1.7.0 with the fix just went live. Thanks for your patience!

BYK avatar May 23 '18 21:05 BYK