Replace use of deprecated/unsafe new Buffer constructor
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
Getting this same warning on macOS. I believe #5704 is a duplicate of this.
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 "$@"
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.
@martinstuecklschwaiger when is the fix done???
@marvinhagemeister v8-compile-cache just released 2.0.0 version, which fixed the bug. Hope we can soon update to new version.
@fengerzh @imsnif already committed the new version to master https://github.com/yarnpkg/yarn/commit/546a1576edbf701021ce65e3dd8daff267083f52 🎉
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.
This warning started popping up after I've upgraded from node v0.9.x to v0.10.1
@piotr-cz you mean v10.1, 0.10 is pretty ancient.
Thanks, I meant that the warning started popping up after upgrade from v9.x to v10.1.0
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
Any progress here? We would really like to use node 10 within our project without any workaround 🔥
It's just a warning. Why would it prevent you from using it?
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
@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.
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.
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.
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.
Update: the above-mentioned PR is now merged. We'll release a new version as soon as possible.
Version 1.7.0 with the fix just went live. Thanks for your patience!