hjdhjd / homebridge-unifi-protect

:video_camera: Complete HomeKit integration for all UniFi Protect device types with full support for most features including HomeKit Secure Video, and more. https://homebridge.io
Other
1.45k stars 93 forks source link

ES Module failed to load after upgrade #486

Closed bls8486 closed 3 years ago

bls8486 commented 3 years ago

Describe The Problem: Homebridge-Unifi-Protect module fails to start up after upgrade to 4.4.1

To Reproduce: Restart homebridge. Attempted to downgrade to 4.4.0, and same error. Updated homebridge to latest oznu image.

Logs: [7/19/2021, 9:16:03 AM] [HB Supervisor] Starting Homebridge with extra flags: -I -P /homebridge/node_modules [7/19/2021, 9:16:03 AM] [HB Supervisor] Started Homebridge v1.3.4 with PID: 1486 Initializing HAP-NodeJS v0.9.4... [7/19/2021, 9:16:04 AM] Loaded config.json with 3 accessories and 2 platforms. [7/19/2021, 9:16:04 AM] Loaded 0 cached accessories from cachedAccessories. [7/19/2021, 9:16:04 AM] --- [7/19/2021, 9:16:05 AM] Loaded plugin: homebridge-dummy@0.5.0 [7/19/2021, 9:16:05 AM] Registering accessory 'homebridge-dummy.DummySwitch' [7/19/2021, 9:16:05 AM] --- [7/19/2021, 9:16:05 AM] ==================== [7/19/2021, 9:16:05 AM] ERROR LOADING PLUGIN homebridge-unifi-protect: [7/19/2021, 9:16:05 AM] Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /homebridge/node_modules/homebridge-unifi-protect/node_modules/node-fetch/src/index.js require() of ES modules is not supported. require() of /homebridge/node_modules/homebridge-unifi-protect/node_modules/node-fetch/src/index.js from /homebridge/node_modules/homebridge-unifi-protect/dist/protect-api.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /homebridge/node_modules/homebridge-unifi-protect/node_modules/node-fetch/package.json.

at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/homebridge/node_modules/homebridge-unifi-protect/src/protect-api.ts:20:1)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)

[7/19/2021, 9:16:05 AM] ==================== [7/19/2021, 9:16:05 AM] Loaded plugin: homebridge-wol@4.3.0 [7/19/2021, 9:16:05 AM] Registering accessory 'homebridge-wol.NetworkDevice' [7/19/2021, 9:16:05 AM] --- [7/19/2021, 9:16:05 AM] Loaded plugin: homebridge-config-ui-x@4.41.1 [7/19/2021, 9:16:05 AM] Registering platform 'homebridge-config-ui-x.config' [7/19/2021, 9:16:05 AM] --- [7/19/2021, 9:16:05 AM] Loading 2 platforms... [7/19/2021, 9:16:05 AM] No plugin was found for the platform "UniFi Protect" in your config.json. Please make sure the corresponding plugin is installed correctly. [7/19/2021, 9:16:05 AM] [Config] Initializing config platform... [7/19/2021, 9:16:05 AM] [Config] Running in Service Mode [7/19/2021, 9:16:05 AM] Loading 3 accessories... [7/19/2021, 9:16:05 AM] [Kitchen Computer] Initializing NetworkDevice accessory... [7/19/2021, 9:16:05 AM] [Work PC] Initializing NetworkDevice accessory... [7/19/2021, 9:16:05 AM] [Home Track] Initializing DummySwitch accessory... [7/19/2021, 9:16:05 AM] [Home Track] Setting switch to true Preparing Advertiser for 'Homebridge CAD8' using bonjour-hap backend! Setup Payload: X-HM://0023I2OY7P2H2 Enter this code with your HomeKit app on your iOS device to pair with Homebridge:

┌────────────┐     
│XXXXXXXXXXX │     
└────────────┘     

Starting to advertise 'Homebridge CAD8' using bonjour-hap backend! [7/19/2021, 9:16:05 AM] Homebridge v1.3.4 (Homebridge) is running on port 51826.

Homebridge Configuration:

{ "controllers": [ { "address": "xxxxxxxxxxxxxxxxx", "password": "xxxxxxxxxxxxxxxx", "username": "xxxxxxxxxxxxxx" } ], "options": [ "Enable.Motion.Trigger", "Enable.Motion.SmartDetect", "Enable.Log.Motion" ], "motionDuration": 20, "platform": "UniFi Protect" },

Screenshots: N/A

Environment:

mvanhelmont commented 3 years ago

same problem here, clean homebridge raspberry pi image. First plugin installed unifi protect and get this message.

hjdhjd commented 3 years ago

I’ll take a look a bit later in the day…I’d suggest not upgrading, given nothing’s changed on the plugin end, I assume there’s some requirement quirk that’s kicked in with the most recent images, assuming none of you guys are running the betas.

mvanhelmont commented 3 years ago

No not running any beta. Fresh install of Homebridge Raspberry Pi Image.. Then installed Homebridge-UniFi-Protect Plugin Version: 4.4.1.

Homebridge Version | v1.3.4 Node.js Version | v14.17.1 Npm Version | v7.17.0

hjdhjd commented 3 years ago

Yep…I am aware of the issue, and a fix will be coming later today.

hjdhjd commented 3 years ago

Fixed in v4.4.2. The issue, for what it's worth, is really an upstream one in one of the other modules that appears to be a release without as much QA as one would hope. Regardless...fixed for us. :smile:

bls8486 commented 3 years ago

Confirmed. I am back up and running with 4.4.2. Thank you sir.

hjdhjd commented 3 years ago

Your welcome...hope you consider paying it forward and supporting a local charity or two.

github-actions[bot] commented 1 year ago

This issue is locked to prevent necroposting on closed issues. Please create a new issue for related support requests, bug reports, or feature suggestions.