简体   繁体   English

WebStorm - 如何在 npm 包中找到问题的根源? (节点:36378)[DEP0005] 弃用警告

[英]WebStorm - How to find source of a problem inside a npm package? (node:36378) [DEP0005] DeprecationWarning

I started getting this error in the last 6 months, probably because of a update to node.js .我在过去 6 个月内开始收到此错误,可能是因为更新了node.js

(node:36378) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. (节点:36378)[DEP0005] 弃用警告:由于安全和可用性问题,不推荐使用 Buffer()。 Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.请改用 Buffer.alloc()、Buffer.allocUnsafe() 或 Buffer.from() 方法。

I've pinpointed the specific package that is causing this warning: https://github.com/irhc/js-logging我已经确定了导致此警告的特定包: https : //github.com/irhc/js-logging

It's no longer maintained so I have to dig down and find the source of this problem.它不再维护,所以我必须深入挖掘并找到这个问题的根源。 However my IDE ( WebStorm ) is not showing any lines of code.但是我的 IDE ( WebStorm ) 没有显示任何代码行。 I also searched the source code and couldn't find Buffer() used anywhere.我还搜索了源代码,但找不到在任何地方使用的Buffer() How can I find the source of this problem?我怎样才能找到这个问题的根源?

Btw I'm also using fs in the same file, which actually has Buffer() inside, but commenting out the dependency and related functions didn't get rid of the warning.顺便说一句,我也在同一个文件中使用了fs ,其中实际上有Buffer() ,但是注释掉依赖项和相关函数并没有消除警告。

Edit: Thanks to the suggestions by @ix3 I lowered the scope of the problem编辑:感谢@ix3 的建议,我降低了问题的范围

  • This doesn't happen while running in node server在节点服务器中运行时不会发生这种情况
  • This doesn't happen while running mocha test from terminal https://prnt.sc/lh012c从终端https://prnt.sc/lh012c运行 mocha 测试时不会发生这种情况
  • This does happen when running mocha tests from Webstorm : https://prnt.sc/lh01acWebstorm运行 mocha 测试时会发生这种情况: https : Webstorm

So the problem is in the interaction of Webstorm + Mocha + Node + js-logging.所以问题出在Webstorm+Mocha+Node+js-logging的交互上。 Each of them work perfectly alone, but I get this error when they are together.他们每个人都可以完美地单独工作,但是当他们在一起时我会收到此错误。

The fact that js-logging is no longer maintained makes it a sensible first place to look. js-logging不再维护的事实使它成为一个明智的首选。 However, if it is not calling new Buffer (and neither are any of its dependencies) then something else must be triggering that warning message.但是,如果它没有调用new Buffer (并且它的任何依赖项都没有),那么一定是其他东西触发了该警告消息。 How did you "pinpoint" the problem to that package?你是如何“查明”这个包的问题的?

You might want to try running your program with a debugger (eg the one built into Chrome) attached.您可能想尝试运行带有调试器(例如 Chrome 内置的调试器)的程序。 You can do this by following the instructions that Paul Irish explains here .您可以按照Paul Irish 在此处解释的说明执行此操作 Also note that Chrome 70 now offers ndb .另请注意,Chrome 70 现在 提供ndb

You can also try "grepping" your entire source tree (including node_modules ) for "new Buffer".您还可以尝试“grepping”整个源树(包括node_modules )以获取“新缓冲区”。 There are multiple ways to do this, and they vary by operating system.有多种方法可以做到这一点,它们因操作系统而异。 For example, on a POSIX system like Linux you can usually do something like grep -drecurse "new Buffer" .例如,在像 Linux 这样的 POSIX 系统上,您通常可以执行类似grep -drecurse "new Buffer" . from the root folder of your project to search for all occurrences of that string in all files within that tree.从项目的根文件夹中搜索该树中所有文件中所有出现的该字符串。

Finally, it bears repeating that the message you listed is not an error but only a warning .最后,值得重申的是,您列出的消息不是错误,而只是警告 Consequently, it is not causing any different behavior.因此,它不会导致任何不同的行为。 In other words, fixing it will only make the message go away;换句话说,修复它只会让消息消失; it will not significantly change the behavior of your program.它不会显着改变您的程序的行为。 Of course, you should still strive to address it as the warning is telling you that in a future version of node the code you have right now will stop working.当然,您仍然应该努力解决它,因为警告告诉您在未来版本的节点中,您现在拥有的代码将停止工作。

Edit : Looking at the audio-less videos you shared, it looks like you are doing all kinds of things that your question didn't mention, eg编辑:查看您共享的无音频视频,看起来您正在做您的问题没有提到的各种事情,例如

  • You are writing in TypeScript (What happens when you use plain JavaScript?)你正在用 TypeScript 编写(当你使用纯 JavaScript 时会发生什么?)
  • You are only running the tests from within the IDE (What happens when you run them from the command line?)您只是在 IDE 中运行测试(当您从命令行运行它们时会发生什么?)

It's quite possible that you are using an old version of ts-node which used the Buffer constructor until about May 2018 .您很有可能使用旧版本的ts-node ,它使用Buffer构造函数直到大约 2018 年 5 月

Aside: To track when dependencies change (especially dependencies of dependencies of ....) I strongly recommend using yarn or at least package-lock.json as otherwise it is completely possible that your app will build and work one day and not the next due to changes upstream.旁白:要跟踪依赖项何时发生变化(尤其是 .... 的依赖项的依赖项),我强烈建议使用yarn或至少使用package-lock.json ,否则您的应用程序完全有可能在某一天而不是下一天构建和工作由于上游的变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (节点:71307)[DEP0079] 弃用警告 - (node:71307) [DEP0079] DeprecationWarning 奇怪的错误代码(节点:8140)[DEP0147] DeprecationWarning: - Weird error code (node:8140) [DEP0147] DeprecationWarning: (节点:93364)[DEP0018] DeprecationWarning:不推荐使用未处理的 promise 拒绝 - (node:93364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated (节点:6868)[DEP0062] DeprecationWarning:不推荐使用`node --inspect --debug-brk` - (node:6868) [DEP0062] DeprecationWarning: `node --inspect --debug-brk` is deprecated Discord.js: (node:4976) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated - Discord.js: (node:4976) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated 如何在 github 上找到节点 package 的旧版本源代码? - How to find the older versions of source code for a node package on github? 如何卸载另一个 npm 包中的 npm 包 - How to uninstall npm package which is inside onother npm package 如何找出节点/npm package 导出了哪些函数? - How do you find out which functions are exported by a node/npm package? 如何在vue npm包中调用函数? - How to call a function inside a vue npm package? 如何在vue中触发npm package里面的方法? - How to trigger a method inside npm package in vue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM