弃用警告:由于安全和可用性问题,不推荐使用 Buffer()。请改用 Buffer.alloc(), ... 方法

Kha*_*mal 16 angular-universal angular

我有一个 angular 项目,最近我使用以下命令向它添加了 angular-universal:

ng add @nguniversal/express-engine --clientProject {{ name of your project }}
Run Code Online (Sandbox Code Playgroud)

构建和运行它:

npm run build:ssr && npm run serve:ssr
Run Code Online (Sandbox Code Playgroud)

这样做后我遇到了很多错误,但我设法让它正常工作,但是当我访问我的主页时,它将以下内容写入控制台:

(node:44714) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
ERROR [Error]
ERROR [Error]
Run Code Online (Sandbox Code Playgroud)

每次我刷新页面时,它都会在ERROR [Error]没有任何细节的情况下再次打印,请注意new Buffer()我的代码中没有任何内容,并且我已经按照堆栈溢出的建议解决了这个问题,但没有运气,有人可以帮助弄清楚是什么吗造成这个?


我已经ERROR [Error]通过删除 TranslateService解决了这个问题,但仍然有 deprecationWarning

Abd*_*man 27

如果您Buffer()在代码中使用,只需将其替换为:

new Buffer(number) // Deprecated 
Buffer.alloc(number) // New
Run Code Online (Sandbox Code Playgroud)

或者

new Buffer(string) // Deprecated 
Buffer.from(string) // New
Run Code Online (Sandbox Code Playgroud)

如果您不在Buffer()任何地方使用,则必须执行以下操作:

1) 搜索您所有的应用程序依赖项(您可以通过单击您当前使用的 IDE 中的搜索图标并键入来使用搜索工具进行搜索Buffer()

2)无论您Buffer()在模块或依赖项中的任何位置找到 a ,都如上所述替换它