Bug 284062 - comms/zigbee2mqtt: zigbee2mqtt-2.0.0 fails to start because of a missing dependency
Summary: comms/zigbee2mqtt: zigbee2mqtt-2.0.0 fails to start because of a missing depe...
Status: In Progress
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Juraj Lutter
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-14 17:17 UTC by Petteri Valkonen
Modified: 2026-11-08 20:57 UTC (History)
7 users (show)

See Also:
bugzilla: maintainer-feedback? (otis)


Attachments
Zigbee2MQTT 2.1.1 (20.02 KB, patch)
2025-02-27 16:12 UTC, yzrh
no flags Details | Diff
testport log (20.02 KB, text/plain)
2025-02-27 16:13 UTC, yzrh
no flags Details
Zigbee2MQTT 2.1.1 (bzip2) (51.62 KB, application/x-bzip)
2025-02-27 16:15 UTC, yzrh
no flags Details
zigbee2mqtt 2.7.1 (bzip2) (62.03 KB, patch)
2025-12-14 16:10 UTC, yzrh
no flags Details | Diff
zigbee2mqtt 2.14.3 (283.10 KB, patch)
2026-11-08 20:57 UTC, Thierry Dussuet
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Petteri Valkonen 2025-01-14 17:17:46 UTC
When trying to start the z2m service with 'service z2m onestart' (on 13.4-RELEASE-p1), the process fails with an error:

Jan 14 19:13:03 unas z2m[16876]: node:internal/modules/cjs/loader:641
Jan 14 19:13:03 unas z2m[16876]:       throw e;
Jan 14 19:13:03 unas z2m[16876]:       ^
Jan 14 19:13:03 unas z2m[16876]:
Jan 14 19:13:03 unas z2m[16876]: Error: Cannot find module '/usr/local/z2m/node_modules/rimraf/dist/commonjs/index.js'
Jan 14 19:13:03 unas z2m[16876]:     at createEsmNotFoundErr (node:internal/modules/cjs/loader:1262:15)
Jan 14 19:13:03 unas z2m[16876]:     at finalizeEsmResolution (node:internal/modules/cjs/loader:1250:15)
Jan 14 19:13:03 unas z2m[16876]:     at resolveExports (node:internal/modules/cjs/loader:634:14)
Jan 14 19:13:03 unas z2m[16876]:     at Module._findPath (node:internal/modules/cjs/loader:724:31)
Jan 14 19:13:03 unas z2m[16876]:     at Module._resolveFilename (node:internal/modules/cjs/loader:1211:27)
Jan 14 19:13:03 unas z2m[16876]:     at Module._load (node:internal/modules/cjs/loader:1051:27)
Jan 14 19:13:03 unas z2m[16876]:     at Module.require (node:internal/modules/cjs/loader:1311:19)
Jan 14 19:13:03 unas z2m[16876]:     at require (node:internal/modules/helpers:179:18)
Jan 14 19:13:03 unas z2m[16876]:     at Object.<anonymous> (/usr/local/z2m/index.js:7:22)
Jan 14 19:13:03 unas z2m[16876]:     at Module._compile (node:internal/modules/cjs/loader:1469:14) {
Jan 14 19:13:03 unas z2m[16876]:   code: 'MODULE_NOT_FOUND',
Jan 14 19:13:03 unas z2m[16876]:   path: '/usr/local/z2m/node_modules/rimraf/package.json'
Jan 14 19:13:03 unas z2m[16876]: }
Jan 14 19:13:03 unas z2m[16876]:
Jan 14 19:13:03 unas z2m[16876]: Node.js v20.18.1
Comment 1 Juraj Lutter freebsd_committer freebsd_triage 2025-01-14 17:42:58 UTC
Is rimraf in PREFIX/z2m/node_modules?

What is the relevant output of

sh -x /usr/local/etc/rc.d/z2m one start
Comment 2 Juraj Lutter freebsd_committer freebsd_triage 2025-01-14 17:45:24 UTC
Nevermind, I was able to reproduce it.
Comment 3 yzrh 2025-02-27 13:19:32 UTC
I just encountered the same problem.  I think the cause is this line,

${FIND} ${WRKSRC}/node_modules -type d -a \( -name build -o -name dist \) -print0 | xargs -0 ${RM} -rf && \

which deleted

/usr/local/z2m/node_modules/rimraf/dist

and thus /usr/local/z2m/node_modules/rimraf/dist/commonjs/index.js

I know the binary size of nodejs programmes look amazing, and there is no
clear way to know what's needed for build time and what's for runtime...
Comment 4 yzrh 2025-02-27 16:12:36 UTC
Created attachment 258033 [details]
Zigbee2MQTT 2.1.1

The patch bumps version to 2.1.1, removed the statement deleting dist and build, and
also includes a workaround for issue

https://github.com/Koenkk/zigbee2mqtt/pull/25202.

without the workaround, the following is observed during startup:

Feb 27 15:20:23 z2m z2m[22850]: /overlay/usr/local/z2m/node_modules/.pnpm/node-gyp-build@4.8.4/node_modules/node-gyp-build/node-gyp-build.js:60
Feb 27 15:20:23 z2m z2m[22850]:   throw new Error('No native build was found for ' + target + '\n    loaded from: ' + dir + '\n')
Feb 27 15:20:23 z2m z2m[22850]:         ^
Feb 27 15:20:23 z2m z2m[22850]: Error: No native build was found for platform=freebsd arch=x64 runtime=node abi=115 uv=1 libc=glibc node=20.18.2
Feb 27 15:20:23 z2m z2m[22850]:     loaded from: /overlay/usr/local/z2m/node_modules/.pnpm/@serialport+bindings-cpp@13.0.1/node_modules/@serialpo
rt/bindings-cpp
Feb 27 15:20:23 z2m z2m[22850]:
Feb 27 15:20:23 z2m z2m[22850]:     at Function.load.resolve.load.path (/overlay/usr/local/z2m/node_modules/.pnpm/node-gyp-build@4.8.4/node_modul
es/node-gyp-build/node-gyp-build.js:60:9)
Feb 27 15:20:23 z2m z2m[22850]:     at load (/overlay/usr/local/z2m/node_modules/.pnpm/node-gyp-build@4.8.4/node_modules/node-gyp-build/node-gyp-
build.js:22:30)
Feb 27 15:20:23 z2m z2m[22850]:     at Object.<anonymous> (/overlay/usr/local/z2m/node_modules/.pnpm/@serialport+bindings-cpp@13.0.1/node_modules
/@serialport/bindings-cpp/dist/serialport-bindings.js:10:48)
Feb 27 15:20:23 z2m z2m[22850]:     at Module._compile (node:internal/modules/cjs/loader:1469:14)
Feb 27 15:20:23 z2m z2m[22850]:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
Feb 27 15:20:23 z2m z2m[22850]:     at Module.load (node:internal/modules/cjs/loader:1288:32)
Feb 27 15:20:23 z2m z2m[22850]:     at Function.Module._load (node:internal/modules/cjs/loader:1104:12)
Feb 27 15:20:23 z2m z2m[22850]:     at Module.require (node:internal/modules/cjs/loader:1311:19)
Feb 27 15:20:23 z2m z2m[22850]:     at require (node:internal/modules/helpers:179:18)
Feb 27 15:20:23 z2m z2m[22850]:     at Object.<anonymous> (/overlay/usr/local/z2m/node_modules/.pnpm/@serialport+bindings-cpp@13.0.1/node_modules
/@serialport/bindings-cpp/dist/load-bindings.js:5:31)
Comment 5 yzrh 2025-02-27 16:13:32 UTC
Created attachment 258034 [details]
testport log
Comment 6 yzrh 2025-02-27 16:15:34 UTC
Created attachment 258035 [details]
Zigbee2MQTT 2.1.1 (bzip2)
Comment 7 yzrh 2025-02-27 16:18:52 UTC
Uploaded the log twice...  It is fixed now.

Because of the plist changes, it is too big for bugzilla so bzip2'd to permit upload.
Comment 8 Juraj Lutter freebsd_committer freebsd_triage 2025-02-27 21:12:29 UTC
did you also test on aarch64?
Comment 9 yzrh 2025-02-27 23:51:17 UTC
I don't have access to that platform.  The only non x86 I have is powerpc64le.
Comment 10 Juraj Lutter freebsd_committer freebsd_triage 2025-03-07 10:42:17 UTC
At the first glance I have a feeling that "pnpm rebuild" should be called from within build target, as there are arch-dependent files in serialport/bindings-cpp that needs to be rebuilt for particular platform/architecture (and thus should not be distributed in distfile).
Comment 11 yzrh 2025-03-08 20:38:32 UTC
Yes, you are right.  But it is not so straightforward, let me
play with `pnpm fetch' and see what can be done.
Comment 12 yzrh 2025-03-25 15:18:34 UTC
There are now two platform dependent node modules.  Calling `pnpm fetch --prod' only,
results in both getting built.  I don't know (yet) how to (ab)use node's build system to
achieve that...

make create-caches-tarball
cd /usr/ports/comms/zigbee2mqtt/work/zigbee2mqtt-2.1.3 &&  /usr/bin/env XDG_DATA_HOME=/usr/ports/comms/zigbee2mqtt/work  XDG_CONFIG_HOME=/usr/ports/comms/zigbee2mqtt/work  XDG_CACHE_HOME=/usr/ports/comms/zigbee2mqtt/work/.cache  HOME=/usr/ports/comms/zigbee2mqtt/work PATH=/usr/ports/comms/zigbee2mqtt/work/.bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin PKG_CONFIG_LIBDIR=/usr/ports/comms/zigbee2mqtt/work/.pkgconfig:/usr/local/libdata/pkgconfig:/usr/local/share/pkgconfig:/usr/libdata/pkgconfig MK_DEBUG_FILES=no MK_KERNEL_SYMBOLS=no SHELL=/bin/sh NO_LINT=YES PREFIX=/usr/local  LOCALBASE=/usr/local  CC="cc" CFLAGS="-O2 -pipe  -fstack-protector-strong -fno-strict-aliasing "  CPP="cpp" CPPFLAGS=""  LDFLAGS=" -fstack-protector-strong " LIBS=""  CXX="c++" CXXFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing  " BSD_INSTALL_PROGRAM="install  -s -m 555"  BSD_INSTALL_LIB="install  -s -m 0644"  BSD_INSTALL_SCRIPT="install  -m 555"  BSD_INSTALL_DATA="install  -m 0644"  BSD_INSTALL_MAN="install  -m 444" pnpm fetch --prod &&  /usr/bin/tar czf /usr/ports/comms/zigbee2mqtt/work/zigbee2mqtt-nodemodules-2.1.3.tar.gz  node_modules pnpm-lock.yaml
Importing packages to virtual store
Already up to date
Progress: resolved 179, reused 0, downloaded 179, added 179, done
node_modules/.pnpm/unix-dgram@2.0.6/node_modules/unix-dgram: Running install script, done in 4.2s
node_modules/.pnpm/@serialport+bindings-cpp@13.0.1/node_modules/@serialport/bindings-cpp: Running install script, done in 7.3s

devDependencies: skipped
Comment 13 Andriy Gapon freebsd_committer freebsd_triage 2025-12-01 12:42:17 UTC
No news for a long time, meanwhile the port is still broken.
Comment 14 Juraj Lutter freebsd_committer freebsd_triage 2025-12-01 13:14:43 UTC
I have some directions to explore.
Comment 15 Andriy Gapon freebsd_committer freebsd_triage 2025-12-02 15:23:10 UTC
(In reply to Juraj Lutter from comment #14)
Meanwhile, is there any workaround to get z2m working (fresh installation)?
Or is a custom build with the attached patch the only option at the moment?
Comment 16 Petteri Valkonen 2025-12-04 20:21:54 UTC
(In reply to Andriy Gapon from comment #15)

While waiting for a fix, I've been running a local installation set up with these commands (a sh-like shell is assumed):

# pkg install node24 npm-node24
# mkdir -p /opt
# cd /opt
# git clone https://github.com/Koenkk/zigbee2mqtt.git
# cd zigbee2mqtt
# npm list -g | head -1
/usr/local/lib
# npm set prefix="$HOME/.local"
# npm list -g | head -1
/root/.local/lib
# npm install -g pnpm@latest-9
# export PATH=$PATH:$HOME/.local/bin
# which pnpm
/root/.local/bin/pnpm
pnpm --version
9.15.9
# pnpm i --frozen-lockfile
# pnpm run build

You can use the rc.d startup script from the port with these settings in rc.conf:

z2m_enable="YES"
z2m_chdir="/opt/zigbee2mqtt"

Finally, start the service with:

# service z2m start
# tail -f /var/log/z2m/current/z2m.log
Comment 17 Andriy Gapon freebsd_committer freebsd_triage 2025-12-08 16:04:46 UTC
(In reply to Petteri Valkonen from comment #16)
Thank you very much!
Comment 18 Andriy Gapon freebsd_committer freebsd_triage 2025-12-09 06:57:39 UTC
(In reply to Petteri Valkonen from comment #16)
The only additional thing I had to do manually was to create /var/log/z2m directory with z2m ownership.  Looks like the package didn't do that, at least not at the installation stage.
Comment 19 Juraj Lutter freebsd_committer freebsd_triage 2025-12-09 21:15:53 UTC
I will fix the directory ownership (although I'm quite sure that it's already done).

The problem is that there are some nodejs bindings, namely for @serialport, that needs to be rebuilt for particular arch.

I'd happily accept any advice or help with proper solution.
Comment 20 yzrh 2025-12-14 16:10:03 UTC
Created attachment 266189 [details]
zigbee2mqtt 2.7.1 (bzip2)

Update patch to 2.7.1.

Poudriere can produce a package, but it only work for the same platform as host.
pmpn rebuild does not accept --cpu flag like pmpn install.  The binary also does not
have different file name (when built on different platform).
Comment 21 Joan Touzet 2026-09-05 20:54:48 UTC
maintainers, any update on this? port is now broken for almost two years. willing to take look, but don't want to step on any feet. meanwhile z2m has progress from 2.0.0 to 2.14.1.
Comment 22 Rene Ladan freebsd_committer freebsd_triage 2026-09-30 21:45:09 UTC
This port expired today because it uses expired node20,
Comment 23 Andriy Gapon freebsd_committer freebsd_triage 2026-10-01 06:22:00 UTC
The latest Z2M actually works just fine with node24, not surprisingly at all.
Running manually installed 1.38.3 here.

But the node version seems to be one of the smaller issues with the port.
Comment 24 Juraj Lutter freebsd_committer freebsd_triage 2026-10-01 06:44:53 UTC
(In reply to Andriy Gapon from comment #23)
True. I did not have any free cycles to correctly update it. You can step up as a maintainer.

The problem is that there are some platform-specific binaries expected to run z2m (in particular, serial port bindings) and they need to be rebuilt either on package time or on first run time.
Comment 25 Andriy Gapon freebsd_committer freebsd_triage 2026-10-01 13:46:39 UTC
(In reply to Juraj Lutter from comment #24)
I am afraid that I won't be able to properly maintain it.
I need to use it and I manage to upgrade my existing installation from time to time, but maintaining such a port would be much more time consuming.

One idea though, maybe a port could be a just a help to setup some environment for Z2M: directories, permissions, accounts, rc.d script, etc.
But a user would still be required to manually run pnpm or Z2M's upgrade script.
So, not a proper port but better than nothing.
Comment 26 Andriy Gapon freebsd_committer freebsd_triage 2026-10-01 18:40:57 UTC
(In reply to Andriy Gapon from comment #23)
Sorry, typed nonsense about the version (it was actually from zoneminder).
The correct version is 2.14.1.
Comment 27 Thierry Dussuet 2026-11-08 20:57:47 UTC
Created attachment 277090 [details]
zigbee2mqtt 2.14.3

Seeing as the port expired, a try to make it work. Maybe others can build upon it to improve it, or at least use the patch to upgrade their current installation.