21

I have an angular project and recently I have added angular-universal to it using the following command:

ng add @nguniversal/express-engine --clientProject {{ name of your project }}

building and running it:

npm run build:ssr && npm run serve:ssr

Ive got many errors after doing so but I managed to get it to work, but when I access my home page its writing the following to the console:

(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]

and each time I refresh the page it print ERROR [Error] again without any details, please note that I don't have any new Buffer() in my code, and I have followed the suggestions on stack overflow to solve this but no luck, can someone help to figure out what's causing this?


I have solved the ERROR [Error] by removing the TranslateService, but still having the deprecationWarning

Khaled Jamal
  • 628
  • 1
  • 6
  • 18
  • Try passing `--trace-warnings` or `--trace-deprecation` options to nodejs when running `server.js` file (you need to modify the `serve:ssr` script). This should help you identify which packages cause problem – David Jul 17 '19 at 09:15
  • @David I don't have serve:ssr script all I do is yarn run serve:ssr , I tried running it like yarn run serve:ssr ----trace-warnings and yarn run --trace-warnings serve:ssr but nothing changed and nothing got printed on the console, can you suggest how to run the trace? – Khaled Jamal Jul 17 '19 at 15:44
  • `serve:ssr` is normally a script defined in `package.json`. Passing the option to yarn is useless, you need to pass it to nodejs – David Jul 18 '19 at 10:14
  • @David thank you its working now I have got an exception caused by the server.js – Khaled Jamal Jul 19 '19 at 08:04
  • Hi @KhaledJamal how did you solve the problem? I am also facing the same issue – Madhavan Sundararaj Dec 20 '19 at 02:23
  • 1
    @MadhavanSundararaj check out the above comments and try to debug the exception, if you got one share I might be able to help – Khaled Jamal Dec 20 '19 at 11:35
  • Does this answer your question? [DeprecationWarning: Buffer() is deprecated due to security and usability issues when i move my script to another server](https://stackoverflow.com/questions/52165333/deprecationwarning-buffer-is-deprecated-due-to-security-and-usability-issues) – Nebojsa Sapic Jan 10 '20 at 13:41
  • @NebojsaSapic No I did not, the above comments helped me to solve the issue – Khaled Jamal Jan 11 '20 at 14:29

2 Answers2

29

In case you're using Buffer() in your code just replace it with:

new Buffer(number) // Deprecated 
Buffer.alloc(number) // New

Or

new Buffer(string) // Deprecated 
Buffer.from(string) // New

In case you're not using Buffer() anywhere you have to do the following:

1) Search all of your app dependencies (You might use a tool for searching by clicking the search icon in the IDE your currently using and type Buffer())

2) Wherever you find a Buffer() in a module or dependency just replace it as mentioned above

Abdulrahman Falyoun
  • 3,676
  • 3
  • 16
  • 43
3

I am getting the same warning, it doesn't seem to affect anything at all. I did the find & replace but guess what, there is nothing in my code (neither in the source nor in the compiled bundle) that matches Buffer() so I am pretty curious about it. I have the latest LTS version of node (12.14.1) but I upgraded npm to 6.13.6 Also I have to say that the client version does not produce that output if deployed to my production or development server, it only happens when serving the SSR version via iisnode, i don't know if that helps.

Sparker73
  • 303
  • 2
  • 10