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
Is rimraf in PREFIX/z2m/node_modules? What is the relevant output of sh -x /usr/local/etc/rc.d/z2m one start
Nevermind, I was able to reproduce it.
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...
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)
Created attachment 258034 [details] testport log
Created attachment 258035 [details] Zigbee2MQTT 2.1.1 (bzip2)
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.
did you also test on aarch64?
I don't have access to that platform. The only non x86 I have is powerpc64le.
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).
Yes, you are right. But it is not so straightforward, let me play with `pnpm fetch' and see what can be done.
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
No news for a long time, meanwhile the port is still broken.
I have some directions to explore.
(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?
(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
(In reply to Petteri Valkonen from comment #16) Thank you very much!
(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.
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.