Several of my users using the swedish holiday app is getting crashes together with Homey 5.0 experimental version. Never had any crashes on the old versions and me code seems to be aligned with the SKD. Anybody that can spot the problem?
/app.js:6
const TodaySwedishHolidayToken = new Homey.FlowToken(‘TodaySwedishHoliday’, {type: ‘boolean’,title: this.homey.__(“TodaySwedishHoliday”)});
^
TypeError: Cannot read property ‘__’ of undefined
at Object. (/app.js:6:112)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module.require (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/index.js:1:191)
at require (internal/modules/cjs/helpers.js:77:18)
at /opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/SDK.js:1:3491
at FSReqCallback.oncomplete (fs.js:167:5)
Tried changing it so it matches SDK3, but that dosent fix it:
/app.js:6
const TodaySwedishHolidayToken = new Homey.FlowToken(‘TodaySwedishHoliday’, {type: ‘boolean’,title: this.homey.__(“TodaySwedishHoliday”)});
^
TypeError: Cannot read property ‘__’ of undefined
at Object. (/app.js:6:112)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module.require (/opt/homey-client/node_modules/homey-apps-sdk-v2/index.js:14:19)
at require (internal/modules/cjs/helpers.js:77:18)
at /opt/homey-client/node_modules/homey-apps-sdk-v2/lib/SDK.js:212:28
at FSReqCallback.oncomplete (fs.js:167:5)
SyntaxError: Unexpected token '('
at wrapSafe (internal/modules/cjs/loader.js:1072:16)
at Module._compile (internal/modules/cjs/loader.js:1122:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at Module.require (/opt/homey-client/node_modules/homey-apps-sdk-v2/index.js:14:19)
at require (internal/modules/cjs/helpers.js:77:18)
at /opt/homey-client/node_modules/homey-apps-sdk-v2/lib/SDK.js:212:28
at FSReqCallback.oncomplete (fs.js:167:5)
--- INFO: se.faboul.svenskahelgdagar has been killed ---
I believe another developer ran into the same problem, for some reason the __ method isn’t available from this.homey. This seems like a bug, because the method is still documented.
Perhaps Homey.__ still works and they forgot to move it. Otherwise, you’ll have to report the issue to Athom and hope they’ll provide a fix soon.
""Thank you for contacting Homey customer support! Your question seems to be developer-related and unfortunately we cannot assist you with these kind of questions.
Luckily Homey has a very active community that is eager to help. You can ask your question on the following resources…"
Ah looking at it a little closer, it may indeed be developer error. It depends on what this refers to in the context of the code where you use it. Can you point to the line of the code in question on Github (provided that you have it stored there)?
When the app.js file is loaded, your app isn’t initialized yet. It isn’t documented (of course), but apparently, you can only use the Homey.__() function after app initialization, which isn’t that weird.
I really, really recommend sticking those variables to some class though, instead of having them floating around in globals… If you stick them in your app class, you can access them everywhere through Homey.app.
It’s a misconception (one that seems to be propagated by Athom themselves) that a variable that gets declared in the outside scope of a module (or .js file) is a global. It’s not.
Globals in Node.js terms are real globals (available from every file without having to import them explicitly), and I don’t think you can even create them from normal code.
Importing modules, like const { Homey } = require('homey'), creates a module-scoped variable, and there’s nothing wrong with that.
In fact, I don’t really like the idea of having a magic this.homey made available in every Homey.* class. It’s way too implicit. It would have been better IMO to pass it as an argument to the constructor, for instance (explicit dependency injection).