Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

visual studio code - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...