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: 2025-12-09 21:15 UTC (History)
3 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

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.