Error updating Ghost with "platform is incompatible with this module" or "warning Resolution field <module> is incompatible with requested version" or "There appears to be trouble with your network connection. Retrying..."

First of all, I apologise for this horror title, but I didn't know how to name it properly, so I just filled it with problems I encountered.

So I have been having this problem for quite a while. At some point, a simple "ghost update" would stop working and produce this kind of error. A whole session would look like this:

# ghost update

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



✔ Checking system Node.js version - found v16.17.0
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking free space
✔ Checking for available migrations
✔ Checking for latest Ghost version

# 5.22.7

* 🐛 Fixed upgrading Subscriptions to new Tiers - Fabien "egg" O'Carroll

---

View the changelog for full details: https://github.com/tryghost/ghost/compare/v5.22.6...v5.22.7

🪄 Love open source? We're hiring [JavaScript Engineers](https://careers.ghost.org/) to work on Ghost full-time

✔ Fetched release notes
✖ Downloading and updating Ghost to v5.22.7
A ProcessError occurred.

Message: Command failed: yarn install --no-emoji --no-progress
warning ghost@5.22.7: The engine "cli" appears to be invalid.
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.29.1"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.29.1"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.29.4"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.29.4"
warning Resolution field "moment-timezone@0.5.23" is incompatible with requested version "moment-timezone@0.5.34"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.29.1"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.29.3"
warning Resolution field "moment-timezone@0.5.23" is incompatible with requested version "moment-timezone@^0.5.33"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.27.0"
warning Resolution field "moment-timezone@0.5.23" is incompatible with requested version "moment-timezone@^0.5.31"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.27.0"
warning Resolution field "@tryghost/logging@2.3.2" is incompatible with requested version "@tryghost/logging@2.2.3"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.29.1"
error @stdlib/utils@0.0.12: The platform "netbsd" is incompatible with this module.
error Found incompatible module.

yarn install v1.22.19
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Exit code: 1


Debug Information:
    OS: unknown, vunknown
    Node Version: v16.17.0
    Ghost Version: 5.13.2
    Ghost-CLI Version: 1.23.1
    Environment: production
    Command: 'ghost update'

No matter what I tried with cache cleaning and switching nodejs between versions 14 and 16, I couldn't update my blogs on either v4 or v5 of Ghost.

I also tried various --ignore statements, as it looked kind of fishy that my self-hosted ghost on NetBSD was suddenly incompatible with standard nodejs modules. Of course, with NetBSD there was a tiny chance that Ghost wasn't officially supported, but come on, it's just software, and all the requirements are met with packages from pkgsrc.

Documentation of yarn install I used:

Yarn
Fast, reliable, and secure dependency management.

Unfortunately, there was no change in how the update (or clean install) ended. Always with failure.

Then I found somewhere that there is another --ignore statement that is somehow undocumented: --ignore-platform

When I run this command in the main ghost directory, all packages are fetched without any problem...

yarn install --ignore-engines --ignore-platform --network-timeout 1000000
Magic command ;)

Another problem I faced was how to pass all these command switches to ghost-cli... Luckily, as you can see in line 29 of the log, there is an exact command that ghost-cli uses:

Message: Command failed: yarn install --no-emoji --no-progress

With "emoji", which is rather unusual for shell commands, I thought it would be relatively easy to find out where it came from. I couldn't find anything except entries in the failure logs in the ghost directory, so I decided to just grep the whole filesystem:

grep -R "--no-emoji" /*

And after dozens of minutes, I got one promising hit with:

const args = ['install', '--no-emoji', '--no-progress'];

If you are curious, the file you are looking for is yarn-install.js in the ghost-cli module and in NetBSD it is located here:

/usr/pkg/lib/node_modules/ghost-cli/lib/tasks/yarn-install.js

So after changing it to:

const args = ['install', '--ignore-engine', '--ignore-platform'];

and running ghost update, I was finally able to update my ghosts without any problems!

Here is the final successful session :)

u-SYS-web02# ghost update

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



✔ Checking system Node.js version - found v14.21.1
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking free space
✔ Checking for available migrations
✔ Checking for latest Ghost version

# 5.33.8

* 🐛 Fixed default email recipients always being "everyone" rather than matching post visibility (#16247) - Kevin Ansfield
* 🐛 Fixed throwing errors during link redirects - Simon Backx

---

View the changelog for full details: https://github.com/tryghost/ghost/compare/v5.33.7...v5.33.8

🪄 Love open source? We're hiring [JavaScript Engineers](https://careers.ghost.org/) to work on Ghost full-time

✔ Fetched release notes
✔ Downloading and updating Ghost to v5.33.8


Checking theme compatibility for Ghost 5.33.8

✔ Your theme is compatible.

You can also check theme compatibility at https://gscan.ghost.org

Please review the full list of breaking changes at https://ghost.org/docs/changes/

⚠ Have you run `ghost backup`?
? Are you sure you want to migrate to Ghost 5.33.8? Yes
✔ Updating to a major version
✔ Stopping Ghost
✔ Linking latest Ghost and recording versions
✔ Restarting Ghost
✔ Removing old Ghost versions
u-SYS-web02#

Hope it helps someone.