I ran into this problem recently when trying to install my first extension via:
composer require sijad/flarum-ext-google-analytics
extension install command I got from here.
I ran out of memory. Looks like a recommended practice is to run a local dev environment, run your composer commands there, then commit your composer.lock with git and pull to your server.
That sounds like a lot of effort. Was the packagist solution above worked on?
I think for Google Analytics I'll just put the tracking code in the Custom Header HTML in admin's Appearance section (will this work?). But for future extensions I'll need a different solution. Digital Ocean frowns on a swap file, though they do have a tutorial on it.