20

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.

3 Answers 3

5

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.

1
  • Hi this is really help full. I got the same Deprecation Warning from fd-slicer. Jul 17, 2021 at 8:29
3

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.

1
  • 1
    Thanks for the response! However when I do the > Developer: Reload Window in the [Extension Development Host] I get the same warning in the main VS Code instance. When I do that command in the main VS Code instance I close the [Extension Development Host]. This makes the debug console clear but does not resolve the error. Restarting the [Extension Development Host] with Ctrl + Shift + F5 lets the warning stay. Aug 19, 2021 at 7:57
1

I hope you have been able to successfully overcome this issue as I have not seen many answers in online forums relating to this type of warning. VS Code is having trouble referencing your node module as you may have either and outdated version of node or double installation causing broken symlinks. This is usually fixed by uninstalling and reinstalling node using brew a couple of times then unlinking and relinking node once the broken symlinks are gone. The following video helps to explain just how to do this.

https://www.youtube.com/watch?v=DAnf4XUUjkg

After that simply restart your IDE and try launching VS code again! Hope this helps.

1
  • Hey thanks for the question! However the fix that you are describing isn't relevant for me. I have updated the question after some new personal findings. I hope this is a fix for others, Thanks! Jul 16, 2021 at 8:19

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.