openhab / openhabian

openHABian - empowering the smart home, for Raspberry Pi and Debian systems
https://community.openhab.org/t/13379
ISC License
820 stars 252 forks source link

Frontail not starting on fresh install #1711

Closed mstormi closed 2 years ago

mstormi commented 2 years ago

Frontail isn't starting. I have no idea why. See https://community.openhab.org/t/oh-3-3-0-frontail-not-starting-after-fresh-installation/138200/12

This nodejs stuff has been an annoying mess ever. I inherited it but for sure would not have chosen to install Frontail myself Someone proficient with this please help. @Interstellar0verdrive ?

I figured that I need to set NODE_ENV=/usr/lib and at least npm install -g /usr/lib/node_modules/frontail cookie cookie-parser socket.io untildify fs-tail-stream CBuffer byline command-exists connect serve-static express-session basic-auth-connect commander daemon-fix41 universal-analytics is-docker configstore to make the system install all the dependencies but I have no idea why it worked earlier without.

[13:21:14] frontail@smarthouse:~$ /usr/lib/node_modules/frontail/bin/frontail --disable-usage-stats --ui-highlight --ui-highlight-preset /usr/lib/node_modules/frontail/preset/openhab_AEM.json --theme openhab_AEM --lines 2000 --number 200 /var/log/openhab/openhab.log /var/log/openhab/events.log /opt/frontail/lib/stats.js:4 const isDocker = require('is-docker'); ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/lib/node_modules/is-docker/index.js from /opt/frontail/lib/stats.js not supported. Instead change the require of index.js in /opt/frontail/lib/stats.js to a dynamic import() which is available in all CommonJS modules. at Object. (/opt/frontail/lib/stats.js:4:18) at Object. (/opt/frontail/index.js:15:20) at Object. (/opt/frontail/bin/frontail:2:1) { code: 'ERR_REQUIRE_ESM' }

WolfgangSn commented 2 years ago

I just did a trial on a fresh Debian 11 VM image. Installed openhabian. Used openhabian-config to install openhab and frontail. frontail was not working. So I removed the frontail nodejs package(s) and used modified commands that are used in openhabian-config to install the modules in the /opt/frontail directory ( npm install; npm update ). After modifying the service file entry ( e.g. references to the module directory ) it looks like frontail can be started.

mstormi commented 2 years ago

and used modified commands that are

what mods exactly ? npm install -g /opt/frontail ?

WolfgangSn commented 2 years ago

instead of: "npm install --force -g" I changed into the /opt/frontail directory and executed "npm install" followed by: "npm update" instead of "npm update --force -g"

Interstellar0verdrive commented 2 years ago

This nodejs stuff has been an annoying mess ever. I inherited it but for sure would not have chosen to install Frontail myself Someone proficient with this please help. @Interstellar0verdrive ?

I am sorry, I have no clues, I just messed around with the css part :(

mstormi commented 2 years ago

as commented on the forum please validate if the latest openHABian works for you

WolfgangSn commented 2 years ago

please validate if the latest openHABian works for you

Just did a test. The cookie package is installed in location of global modules. Starting frontail it is not found. Other modules are not installed.

I am wondering when the -g flag was introduced to install the packages. If it always has been there could it be that it's not possible any longer to use a link to point from /usr/lib/nodes_modules/frontail to /opt/frontail ?

My installation of frontail ( based on directory timestamps ) is from 10.08.2021. At that time the nodes_modules directory is located under /opt/frontail. With the current setup this directory does not exist but it is created when I modify nodejs-apps.bash as stated in my earlier posts.

mstormi commented 2 years ago

For me it worked on a fresh install. But it's totally intransparent how nodejs handle this, plus nodejs version changed. That's the thing: noone knows for sure. Try setting NODE_PATH env variable via systemd Environment=... See if that makes a difference.

WolfgangSn commented 2 years ago

No. The module installation itself does not work here - at least not yet. g**gle search results also did not help till now.

WolfgangSn commented 2 years ago

@mstormi , what is the output of npm list -g in your case ? Does it show something like:

corepack
frontail -> ../../../opt/frontail
npm

In case I run npm install, npm fix --force followed by npm install -g then the provided service file can be used. The modules are installed in /opt/frontail/node_modules with the first command. The second takes care to update the modules with regard to the used npm version and the global install just creates a link ( /lib/node_modules/frontail ) that points to /opt/frontail/node_modules.

mstormi commented 2 years ago

I believe you mean "audit fix" ? I've added an audit fix command to openHABian, seems to work for me. Please check if that makes a difference for you on a fresh install.

WolfgangSn commented 2 years ago

Please check if that makes a difference for you on a fresh install.

Tested on Debian Bullseye x64 in a VM:

Frontail is running with this version of openhabian-config. There is a difference in number of modules that are installed in the frontail node_modules directory: 118 in my install from last year; 12MB 381 in the test environment; 86MB

mstormi commented 2 years ago

Worked for me on RPi, too so I assume this was a proper fix.