I get an error when I try to package my game

As the message says, you ran out of memory.

Usually, this is due to using compressed cooked packages in the publish settings.

Could be a billion other reasons though.
Check how much the number is with a copy paste and conversion to GB.
Make sure your PC has at least that much physical ram.

If you have around 64gb you’d essentially never see those issues.
Not everyone maxes their ram out…