NetBSD nodejs18 and IPv6

NetBSD nodejs18 and IPv6

This is cross-post from my blog in polish devoted to NetBSD

I run several blogs. All under NetBSD as the OS, and Ghost CMS.

This type of stack is not officially supported, but since we have nodejs in pkgsrc along with npm and yarn, why shouldn't it work in principle? Well it did work, with more or less problems, which I described here.

This was the case until version 5.70.2 or so, as it ran on NodeJS 16. After that version, or shortly after that version, Ghost moved to NodeJS 18 and it is currently the only supported version.

NodeJS 18 favours IPv6 over IPv4. And this is where the strange ride starts, I don't know if it's only with NetBSD or on other systems. Namely - despite:

  • unconfiguring even link-local on the network card
  • setting options in .npmrc or .yarnrc or in nodejs itself
  • recompiling the kernel to disable IPv6 altogether
  • commenting out the localhost IPv6 address in /etc/hosts
  • using ChatGPT and Gemini proposals to force the use of ipv4 by setting shell variables

This had absolutely no effect.

Every installation ended more or less like this:

# ghost update

✖ Checking for Ghost-CLI updates
An error occurred.
Message: 'connect EHOSTUNREACH 2606:4700::6810:1e22:443 - Local (:::65525)'

I got my first breakthrough when I found the --dns-result-order option in the nodejs configuration, which can be set to ipv4first. Despite various attempts with exporting and appending to various .*.rc files, it didn't work as expected, but running ghost update as a parameter to node with this option already did!

node --dns-result-order=ipv4first /usr/pkg/bin/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 v18.19.1
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking free space
✔ Checking for available migrations
✔ Checking for latest Ghost version

# 5.82.0

* 🔒 Added escaping to member export CSV fields - Daniel Lockyer
* 🐛 Fixed jerky scrolling in Site Design for Safari (#19974) - Ronald Langeveld

---

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

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

Message: Command failed: yarn install --no-emoji --no-progress
warning ../../package.json: No license field
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.29.1"
warning Resolution field "@tryghost/errors@1.3.1" is incompatible with requested version "@tryghost/errors@1.2.26"
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.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.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 "@tryghost/errors@1.3.1" is incompatible with requested version "@tryghost/errors@1.2.26"
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 "@tryghost/logging@2.4.13" is incompatible with requested version "@tryghost/logging@2.4.10"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.29.1"
error An unexpected error occurred: "https://registry.npmjs.org/@tryghost/errors/-/errors-1.3.1.tgz: connect EHOSTUNREACH 2606:4700::6810:123:443 - Local (:::65526)".

yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
info If you think this is a bug, please open a bug report with the information provided in "/var/www/node/netbsd.pl/versions/5.82.0/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Of course the joy was short-lived, because when downloading the yarn package (which uses a URL from npm?) it again wants to use an IPv6 address ....

SOLUTION

Eventually I managed to get ghost cli working again, by adding the following lines to /etc/hosts:

104.16.24.34            registry.yarnpkg.com
104.16.2.35             registry.npmjs.org
104.20.23.46            nodejs.org

Fortunately, what is in the hosts file always wins out over the DNS logic of the system and other programs. Interestingly in the system ping, or nslookup of these domains, as much as possible is queried after IPv4 with no problem, so I conclude that the problem lies in NodeJS 18. I don't know if it's possible to correctly force the use of IPv4 only in NodeJS 18/NPM/YARN, the internet itself doesn't provide a straightforward answer on how to configure this, the AI bots completely fail to deal with this problem either.

In general, if Ghost wasn't such a cool blogging engine, I'd have long since given up trying to tame NodeJS, as everything about it is terribly chaotic and any attempt to get more information boils down to someone not having something installed, or running, or trying to e.g. restart the server....

I'm finishing updating the blogs and pkgsrc packages on the already new NetBSD 10 on the test machine, and if everything goes smoothly I'll port the changes to the target machine.

Read more