Skip to content

Memory limit exceeded during ghost install process #1898

@danieldinter

Description

@danieldinter

Summary

My Ghost blog is running on a virtual machine provided by an internet hosting service. They limit single processes to 1.5 GB memory usage. Processes exceeding 1.5 GB memory are automatically killed.

When I try to upgrade Ghost from v5.86.2 to the recent version (i.e. v5.100.1) using the Ghost CLI, the process is killed due to memory usage during the step that says
Installing dependencies > [5/5] Building fresh packages...

Steps to Reproduce & Log File

I switched away from trying to upgrade my blog (as it fails) to setting up a new blog on a green field on the same machine. That makes testing easier.

  1. Run the install command (notice the "Killed" at the end):
$ ghost install --no-stack --no-setup-linux-user --no-setup-systemd --no-setup-nginx --no-setup-mysql --no-start --no-enable

Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org

✔ Checking system Node.js version - found v18.20.4
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
☲ Downloading and installing Ghost v5.100.1 > Installing dependencies > [5/5] Building fresh packages...Killed
  1. Switch to current version directory: $ cd versions/5.100.1/
  2. Try to build dependencies manually (also gets killed):
$ yarn install
yarn install v1.22.22
[1/5] Validating package.json...
warning [email protected]: The engine "cli" appears to be invalid.
[2/5] Resolving packages...
warning Resolution field "[email protected]" is incompatible with requested version "moment@^2.29.1"
warning Resolution field "[email protected]" is incompatible with requested version "moment@^2.29.4"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "moment@^2.27.0"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "jackspeak@^3.1.2"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/[email protected]"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/errors@^1.3.6"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/errors@^1.3.6"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/errors@^1.3.6"
warning Resolution field "[email protected]" is incompatible with requested version "[email protected]"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/[email protected]"
warning Resolution field "@tryghost/[email protected]" is incompatible with requested version "@tryghost/[email protected]"
warning Resolution field "[email protected]" is incompatible with requested version "moment@^2.29.1"
[3/5] Fetching packages...
warning [email protected]: The engine "bun" appears to be invalid.
warning [email protected]: The engine "deno" appears to be invalid.
[4/5] Linking dependencies...
warning " > [email protected]" has incorrect peer dependency "knex@>=0.15.0 <0.22.0".
[5/5] Building fresh packages...
[-/6] ⠄ waiting...
[-/6] ⠄ waiting...
[-/6] ⠄ waiting...
Killed⠄ re2

The messages showing before the kill were:

[5/5] Building fresh packages...
[-/6] ⠂ waiting...
[-/6] ⠂ waiting...
[-/6] ⠂ waiting...
[4/6] ⠄ re2
[6/6] ⠄ @sentry/profiling-node

As it became apparent that memory could be a problem, I tried to set the NODE_OPTIONS parameter --max-old-space-size=1024:

  1. I tried setting it in ~/.npmrc: node-options=--max-old-space-size=1024
  2. I tried setting an environment variable:
$ export NODE_OPTIONS="--max-old-space-size=1024"
$ ghost install …

However, the parameter is not passed by node to yarn. The builds failed again. Although yarn lists the parameter:

$ yarn config list
yarn config v1.22.22
info yarn config
{
 ...
}
info npm config
{
  'node-options': '--max-old-space-size=1024',
  ...
}
Done in 0.07s.

The only way that works is using cross-env:

$ npm i -g cross-env
$ cross-env NODE_OPTIONS=--max-old-space-size=1024 yarn install

That way, the yarn install command finishes regularly. However, I cannot continue the Ghost CLI install process from this point, as it tells me the directory is non-empty:

$ ghost install --no-stack --no-setup-linux-user --no-setup-systemd --no-setup-nginx --no-setup-mysql --no-start --no-enable
Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org

A SystemError occurred.

Message: Current directory is not empty, Ghost cannot be installed here.

Debug Information:
    OS: CentOS Linux, v7
    Node Version: v18.20.4
    Ghost-CLI Version: 1.26.1
    Environment: production
    Command: 'ghost install --no-stack --no-setup-linux-user --no-setup-systemd --no-setup-nginx --no-setup-mysql --no-start --no-enable'

Try running ghost doctor to check your system for known issues.

You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.

Solutions

If I may I like to propose two solutions:

  1. Support cross-env to pass node parameters to yarn.
  2. Allow manual build of dependencies, e.g. by adding a switch to Ghost CLI that ignores non-empty directories.

Technical details

This is automatically output by Ghost-CLI if an error occurs, please copy & paste:

  • OS: CentOS Linux 7 (Core)
  • Node Version: v18.20.4
  • Ghost-CLI Version: 1.26.1
  • Environment: production
  • Command: install

Bug submission checklist

Please fill out this checklist to acknowledge that you followed the requirements to submit a bug report.

  • Tried to find help in the forum & docs
  • Checked for existing issues
  • Attached log file
  • Provided technical details incl. operating system

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions