# Swedish holiday app crashing on homey 5.0 exper

**URL:** <https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929>\
**Category:** Developers\
**Created:** [July 28, 2020, 2:58pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929 "2020-07-28T14:58:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sammyj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sammyj/32/11012_2.png) [@Sammyj](https://community.homey.app/u/Sammyj)\
**Post date:** [July 28, 2020, 2:58pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/1 "2020-07-28T14:58:56Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [July 28, 2020, 4:12pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/2 "2020-07-28T16:12:14Z")

</div>

> [@Sammyj](#):
>
> ad property ‘\_\_’ of undefined

It seems that underscore “\_” is not allowed here (anymore?)

---

<div class="post-metadata">

**Author:** ![Sammyj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sammyj/32/11012_2.png) [@Sammyj](https://community.homey.app/u/Sammyj)\
**Post date:** [July 28, 2020, 4:33pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/3 "2020-07-28T16:33:28Z")

</div>

Same problem if i remove ☹

─────────────── Logging stdout & stderr ───────────────  
/app.js:5  
console.log( Homey.(“title”) ); // “Hello World”  
^

```
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 ---
```

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 29, 2020, 6:34am UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/4 "2020-07-29T06:34:12Z")

</div>

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](https://apps-sdk-v3.developer.athom.com/tutorial-Internationalization.html).

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.

---

<div class="post-metadata">

**Author:** ![Sammyj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sammyj/32/11012_2.png) [@Sammyj](https://community.homey.app/u/Sammyj)\
**Post date:** [July 30, 2020, 11:26am UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/5 "2020-07-30T11:26:50Z")

</div>

Thanks! The response from homey support is

> ""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…"

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 30, 2020, 11:29am UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/6 "2020-07-30T11:29:23Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Tangodelta](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tangodelta/32/9471_2.png) [@Tangodelta](https://community.homey.app/u/Tangodelta)\
**Post date:** [July 30, 2020, 2:45pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/7 "2020-07-30T14:45:36Z")

</div>

App has probably covid-19

---

<div class="post-metadata">

**Author:** ![Sammyj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sammyj/32/11012_2.png) [@Sammyj](https://community.homey.app/u/Sammyj)\
**Post date:** [August 5, 2020, 8:16pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/8 "2020-08-05T20:16:19Z")

</div>

At the moment the code looks like this, see row 6

> <https://github.com/sammyjo86/SwedishRedDays/blob/master/app.js>

---

<div class="post-metadata">

**Author:** ![Sammyj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sammyj/32/11012_2.png) [@Sammyj](https://community.homey.app/u/Sammyj)\
**Post date:** [August 5, 2020, 8:18pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/9 "2020-08-05T20:18:27Z")

</div>

Notice that this was a working code with no bug reports until Homey 5.0

---

<div class="post-metadata">

**Author:** ![Sammyj](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sammyj/32/11012_2.png) [@Sammyj](https://community.homey.app/u/Sammyj)\
**Post date:** [August 5, 2020, 8:27pm UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/10 "2020-08-05T20:27:43Z")

</div>

Solved it now! moved All the const’s in “//Create tokens” to begin after oninit :=)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [August 6, 2020, 6:31am UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/11 "2020-08-06T06:31:00Z")

</div>

So `Homey.__` outside of your class doesn’t work, but _inside_ your class it does?

---

<div class="post-metadata">

**Author:** ![Joolee](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/joolee/32/3064_2.png) [@Joolee](https://community.homey.app/u/Joolee)\
**Post date:** [August 6, 2020, 7:50am UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/12 "2020-08-06T07:50:26Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [August 6, 2020, 8:21am UTC](https://community.homey.app/t/swedish-holiday-app-crashing-on-homey-5-0-exper/32929/13 "2020-08-06T08:21:10Z")

</div>

> [@Joolee](#):
>
> …instead of having them floating around in globals…

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).
