jvmahon / Homebridge-HomeSeer4

Homebridge Plugin for HomeSeer 3 and 4
28 stars 8 forks source link

Getting ERR_REQUIRE_ESM on plugin start #160

Closed ken-wolfe closed 2 years ago

ken-wolfe commented 2 years ago

I just installed Homebridge as a docker container on my synology from oznu. I am running Homebridge 1.3.8 and Homebridge UI. I installed the Homebridge-Homeseer4 version 1.0.21 as well. After configuring a few things and restarting Homebridge I get the error below. Node version is 16.13.0. Npm version is 8.1.0.

After it failed, I tried install the Ring plugin, and that works just fine (just to see if anything would work). My phone shows everything as you would expect from that plugin.

`[11/28/2021, 2:53:40 PM] ==================== [11/28/2021, 2:53:40 PM] ERROR LOADING PLUGIN homebridge-homeseer4: [11/28/2021, 2:53:40 PM] Error [ERR_REQUIRE_ESM]: require() of ES Module /homebridge/node_modules/homebridge-homeseer4/node_modules/chalk/source/index.js from /homebridge/node_modules/homebridge-homeseer4/index.js not supported.

Instead change the require of /homebridge/node_modules/homebridge-homeseer4/node_modules/chalk/source/index.js in /homebridge/node_modules/homebridge-homeseer4/index.js to a dynamic import() which is available in all CommonJS modules. at Object. (/homebridge/node_modules/homebridge-homeseer4/index.js:5:13) at Plugin.load (/usr/local/lib/node_modules/homebridge/lib/plugin.js:132:77) at PluginManager.initializeInstalledPlugins (/usr/local/lib/node_modules/homebridge/lib/pluginManager.js:64:30) at async Server.start (/usr/local/lib/node_modules/homebridge/lib/server.js:106:9) [11/28/2021, 2:53:40 PM] ====================`

ken-wolfe commented 2 years ago

It looks like chalk version 5 (which just published 3 days ago) is now an ES module. Maybe going back to 4.1.2 will fix it at least for now.

ken-wolfe commented 2 years ago

Through a bit of hackery, I managed to update the package.json file to force chalk to use 4.1.2. node-fetch is still forced to 2.6.1 and running npm outdated shows the following:

/homebridge/node_modules/homebridge-homeseer4 # npm outdated Package Current Wanted Latest Location Depended by chalk 4.1.2 4.1.2 5.0.0 node_modules/chalk homebridge-homeseer4 node-fetch 2.6.1 2.6.1 3.1.0 node_modules/node-fetch homebridge-homeseer4

I am getting the this: Failed to fetch HomeSeer device and control data, retrying in 15 seconds... [11/28/2021, 4:23:57 PM] [homebridge-homeseer4] This plugin is taking long time to load and preventing Homebridge from starting. See https://git.io/JtMGR for more info.

Any ideas?

ken-wolfe commented 2 years ago

Apparently, it didn't like my host name. I fixed that now. I've got another issue which is very different (something about the battery and my thermostat). I will submit a PR for the minor change needed.

jvmahon commented 2 years ago

I'll do an update to package.json and re-publish.

jvmahon commented 2 years ago

Done. Update to 1.0.22.

All included packages are now "fixed" to their current version so that this hopefully won't happen again as other packages are updated to ESM modules.