Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode extension: deprecation warning `Buffer()`, how to diagnose

I am rebuilding my comment highlighter in to a new extension.
However I now run now in to an issue where I get the following warning:

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

So far I can find in my extension I never use the function Buffer()
I think that it comes from the vscode module.

When the warning occurs block comment highlighting stops working.

This issue is breaking for my extension in development mode.
However my old extension has the same issue in development mode and released version.
Only in the released version doesn't report of the warning.

I am sorry for not including a minimal, reproducible example.

UPDATE:

In the latest release of my comment highlighter I have fixed block comment highlighting. At least I have fixed what was broken on my end.

The (node:4904) [DEP0005] DeprecationWarning keeps breaking my extension on rare occasions, this happens in all my environments.

Restarting vscode or rebooting the operating system can sometimes fix it. I have noticed that other extensions break as well when my extension is broken.

Operating systems I run:

  • Windows 10
  • Ubuntu 20 LTS

On both OSes I run nvm to manage node and npm versions. I currently have 2 computers both dual booted with the named OSes The issue occurs on both computers.

like image 491
TessavWalstijn Avatar asked Aug 31 '20 15:08

TessavWalstijn


People also ask

How can I see warnings in VS Code?

You can click on the summary or press Ctrl+Shift+M to display the PROBLEMS panel with a list of all current errors. If you open a file that has errors or warnings, they will be rendered inline with the text and in the overview ruler.

Why my VS Code extension is not working?

The solution was to go to Windows PowerShell and open Visual Studio Code, then go to the extensions and restart the Remote - WSL extension, and go back to WSL. It then started working immediately.

Why is my buffer class deprecated?

[error] [Extension Host] (node:61654) [DEP0005] DeprecationWarning: Buffer () is deprecated due to security and usability issues. Please use the Buffer.alloc (), Buffer.allocUnsafe (), or Buffer.from () methods instead.

Does buffer warning affect the functionality of my extension?

For me, this Buffer warning is currently an irritant only, and does not affect the functionality of my extension fortunately. Show activity on this post. I encountered a somewhat similar incident while trying to create my first extension.

How do I fix a buffer () error in an extension?

Obviously, if your extension directly used new Buffer () you can fix it. If you imported/required an extension that uses new Buffer () you have a couple of options: look for an alternative, fork it or file an issue with that repository. In my case, neither of the above was the issue.

Is it safe to use the deprecated/unsafe buffer constructor?

The use of the deprecated new Buffer() constructor (i.E. as used by Yarn) can cause deprecation warnings. Therefore one should NOT use the deprecated/unsafe Buffer constructor. According to the deprecation warning new Buffer() should be replaced with one of: Another option in order to avoid this issue would be using the safe-buffer package instead.


2 Answers

Here are the steps I used to help diagnose what is causing that Buffer deprecation warning.

  1. Uninstall your extension. You may have to reload vscode after this.
  2. Terminal: export NODE_OPTIONS=--throw-deprecation
  3. Terminal: code-insiders --install-extension arturodent.find-and-transform
    (or code --install-extension arturodent.find-and-transform if not on Insiders)

(replace with your extension id found in the package.json)

That should re-install the extension with a stack trace about the deprecation warning.

buffer deprecation warning

Obviously, if your extension directly used new Buffer() you can fix it.

If you imported/required an extension that uses new Buffer() you have a couple of options: look for an alternative, fork it or file an issue with that repository.

In my case, neither of the above was the issue. You can see that fd-slicer is the problem. And that is a dependency of yauzl. yauzl is used by vscode itself, not by me or by my extension's dependencies.

There are issues filed on fd-slicer (maintainer has no interest in fixing this, PR to fix) and on yauzl urging to switch to a forked fd-slicer2 which hasn't been merged yet (PR to fix - consider upvoting). And on vscode: buffer warning, yauzl.

My node version: v15.9.0

For me, this Buffer warning is currently an irritant only, and does not affect the functionality of my extension fortunately.

like image 193
Mark Avatar answered Sep 20 '22 14:09

Mark


I encountered a somewhat similar incident while trying to create my first extension. So launching the Command Palette - Ctrl + Shift + P and selecting >Developer: Reload Window helped.

like image 41
Tafadzwa Chimberengwa Avatar answered Sep 22 '22 14:09

Tafadzwa Chimberengwa