# Debug app code

**URL:** <https://community.homey.app/t/debug-app-code/33516>\
**Category:** Developers\
**Created:** [August 12, 2020, 8:59am UTC](https://community.homey.app/t/debug-app-code/33516 "2020-08-12T08:59:46Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Gruijter](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gruijter/32/1973_2.png) [@Gruijter](https://community.homey.app/u/Gruijter)\
**Post date:** [February 15, 2023, 10:03pm UTC](https://community.homey.app/t/debug-app-code/33516/22 "2023-02-15T22:03:33Z")

</div>

I also cannot use breakpoints with HP2023. I get some message on an unbound breakpoint cannot be set. I tried both --remote and docker.

With HP2016 it does work however. But there I get a message about 32bit not supporting async stuff.

---

<div class="post-metadata">

**Author:** ![DaneedeKruyff](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/daneedekruyff/32/964_2.png) [@DaneedeKruyff](https://community.homey.app/u/DaneedeKruyff)\
**Post date:** [February 16, 2023, 6:20am UTC](https://community.homey.app/t/debug-app-code/33516/23 "2023-02-16T06:20:45Z")

</div>

At the moment I’m working on updating the Ring app to SDK3, I’m doing that on an older Homey so to not run into differences between the old and new Homey so I haven’t tried these settings yet on my new Homey.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [February 16, 2023, 6:22am UTC](https://community.homey.app/t/debug-app-code/33516/24 "2023-02-16T06:22:28Z")

</div>

> [@DaneedeKruyff](#):
>
> `"remoteRoot": "/app/"`

Breakpoints are working for me on HP23 after setting the remote folder like ind Danees example:

```auto
"remoteRoot": "/app/"

```

---

<div class="post-metadata">

**Author:** ![Peter\_Hendrix](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_hendrix/32/8090_2.png) [@Peter\_Hendrix](https://community.homey.app/u/Peter_Hendrix)\
**Post date:** [April 1, 2023, 3:58pm UTC](https://community.homey.app/t/debug-app-code/33516/25 "2023-04-01T15:58:24Z")

</div>

Almost there I think. But the app won’t really run and I cannot sent breakpoints and get: “Starting inspector on 0.0.0.0:9225 failed: address already in use”

So still miles away 😄

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [April 1, 2023, 5:39pm UTC](https://community.homey.app/t/debug-app-code/33516/26 "2023-04-01T17:39:12Z")

</div>

> [@Peter\_Hendrix](#):
>
> “Starting inspector on 0.0.0.0:9225 failed: address already in use”

Do you have some morte details so we can help?

- HP19 or HP23?
- If HP23, is the app running on Homey (homey app run --remote) or in Docker (homey app run)?

Your error message says that there is already a debugger process running on this port.  
If you have more than on app running in debug mode, make sure you are using unique ports for every app.  
If you are trying to start the debugger on HP23 Docker, it won’t work because the process is already started. You must connect to this process instead.

---

<div class="post-metadata">

**Author:** ![Adrian\_Rockall](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/adrian_rockall/32/13209_2.png) [@Adrian\_Rockall](https://community.homey.app/u/Adrian_Rockall)\
**Post date:** [April 1, 2023, 9:45pm UTC](https://community.homey.app/t/debug-app-code/33516/27 "2023-04-01T21:45:17Z")

</div>

If you are running on an HP 2023 use “homey app run --remote” else it will run in Docker which already has inspector running.

You could also try a different port instead of 9225 just in case another app is using it.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [April 2, 2023, 7:31am UTC](https://community.homey.app/t/debug-app-code/33516/28 "2023-04-02T07:31:38Z")

</div>

@Peter_Hendrix  
Here is example code that tries first to connect (docker) or starts debugger (Homey).

> [@Debug app code](https://community.homey.app/t/debug-app-code/33516/17):
>
> Another hint…if you want to debug on Homey and Docker, you can add this code to your app.js: if (process.env.DEBUG === '1'){ try{ require('inspector').waitForDebugger(); } catch(error){ require('inspector').open(9225, '0.0.0.0', true); } } It first tries to connect to an existing debugger prozess (needed for docker) and opens a new one if not found (needed for Homey19 or Homey23 remote). In lauch.json you can provide different profiles for Homey remote or docker…

---

<div class="post-metadata">

**Author:** ![Peter\_Hendrix](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_hendrix/32/8090_2.png) [@Peter\_Hendrix](https://community.homey.app/u/Peter_Hendrix)\
**Post date:** [April 3, 2023, 7:01am UTC](https://community.homey.app/t/debug-app-code/33516/29 "2023-04-03T07:01:59Z")

</div>

Fiddled around a bit and got it working… thanks.  
This speeds up development quite a lot.

---

<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:** [June 9, 2023, 6:24pm UTC](https://community.homey.app/t/debug-app-code/33516/30 "2023-06-09T18:24:02Z")

</div>

You’re a genius!  
The `waitForDebugger` line is probably needed when debugging SDKv3 apps because the execution order for the `onInit` methods has been changed.  
I ran onto the problem of non-binding breakpoints while trying to update my app to SDKv3 and setting a break-point early on in the app execution, running on a 2016 Homey.

---

<div class="post-metadata">

**Author:** ![grant\_violetultra](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/grant_violetultra/32/78901_2.png) [@grant\_violetultra](https://community.homey.app/u/grant_violetultra)\
**Post date:** [October 19, 2023, 10:20am UTC](https://community.homey.app/t/debug-app-code/33516/31 "2023-10-19T10:20:13Z")

</div>

Hi all. Has anyone got this working with a Typescript app instead of JS? I’ve got as far as being able to attach the debugger, but can’t set breakpoints (they’re shown as a grey circle). The diagnostics shows the following:

![Screenshot 2023-10-19 at 09.19.03](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/3/d/3d92810141a9a57dffce106924de445101f8b063.png)

I’m assuming that the `tsconfig.json` file will have no effect on `homey app run`. Another option is to pass `--sourcemap` to the typescript compiler, but how is that possible when it is compiled by `homey app run` ?

I’m also getting the “Warning: Async stack traces in debugger are not available on 32bit platforms” warning, but would that prevent breakpoints from being set?

Thanks in advance for any assistance.

---

<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:** [October 19, 2023, 11:16am UTC](https://community.homey.app/t/debug-app-code/33516/32 "2023-10-19T11:16:08Z")

</div>

> [@grant\_violetultra](#):
>
> I’m assuming that the `tsconfig.json` file will have no effect on `homey app run`.

Instead of assuming, have you tried?

---

<div class="post-metadata">

**Author:** ![grant\_violetultra](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/grant_violetultra/32/78901_2.png) [@grant\_violetultra](https://community.homey.app/u/grant_violetultra)\
**Post date:** [October 19, 2023, 11:32am UTC](https://community.homey.app/t/debug-app-code/33516/33 "2023-10-19T11:32:13Z")

</div>

Hi @robertklep yes, I have. It looks like `tsconfig.json` is used to provide compiler options for when compiling within VSCode. I don’t think the Homey build/run process will be aware of it.

---

<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:** [October 19, 2023, 11:35am UTC](https://community.homey.app/t/debug-app-code/33516/34 "2023-10-19T11:35:12Z")

</div>

If you had tried, you’d have found that adding `"sourceMap": true` to the compiler options in `tsconfig.json` causes source map files to be created in the `.homeybuild` folders, just as the hint suggests…

```auto
$ la .homeybuild/
total 28
drwxrwxr-x 12 robert wheel 384 Oct 19 13:15 ./
drwxrwxr-x 16 robert wheel 512 Oct 19 13:35 ../
-rw-rw-r-- 1 robert wheel 43 Oct 19 13:15 README.md
-rw-rw-r-- 1 robert wheel 34 Oct 19 13:15 README.txt
-rw-rw-r-- 1 robert wheel 510 Oct 19 13:15 app.js
-rw-rw-r-- 1 robert wheel 271 Oct 19 13:15 app.js.map

```

---

<div class="post-metadata">

**Author:** ![grant\_violetultra](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/grant_violetultra/32/78901_2.png) [@grant\_violetultra](https://community.homey.app/u/grant_violetultra)\
**Post date:** [October 19, 2023, 11:44am UTC](https://community.homey.app/t/debug-app-code/33516/35 "2023-10-19T11:44:13Z")

</div>

Ok, thanks, I saw those but hadn’t realised that they weren’t present before I had added it.

I’ve now seen another error message after stopping the debugger - “Could not read source map for file:///app.js: ENOENT: no such file or directory, open ‘/Users/grant/violet/HomeyApp/com.violet-ultra.smartswitch/app.js.map’”  
So, it’s looking for the map files in the root dir (the same one as the .ts source files), not the `.homeybuild` dir. So that’s a step forward.

---

<div class="post-metadata">

**Author:** ![grant\_violetultra](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/grant_violetultra/32/78901_2.png) [@grant\_violetultra](https://community.homey.app/u/grant_violetultra)\
**Post date:** [October 19, 2023, 12:17pm UTC](https://community.homey.app/t/debug-app-code/33516/36 "2023-10-19T12:17:39Z")

</div>

I’ve got it working by updating `"localRoot"` in `launch.json` to be  
`"localRoot": "${workspaceFolder}/.homeybuild",`

Thanks for the help @robertklep

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [September 20, 2024, 5:23am UTC](https://community.homey.app/t/debug-app-code/33516/37 "2024-09-20T05:23:25Z")

</div>

So from all your comments, for someone unexperienced like me…

**How to debug in VSCode**

1. create launch.json - VSCode

- choose RUN AND DEBUG and select settings.  
 ![obrazek](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/1/b10e1a132407fac762966c74c8bdc64aa68f2c33.png)

```auto
{
"version": "0.2.0",
     "configurations": [{
             "name": "Launch app",
             "type": "node",
             "request": "launch",
             "cwd": "${workspaceFolder}",
             "runtimeExecutable": "homey",
             "args": ["app", "run", "--remote"],
             "outputCapture": "std",
             "env": {
                "DEBUG": "1"
            },
             "serverReadyAction": {
                 "pattern": "Debugger listening on",
                 "action": "startDebugging",
                 "name": "Attach to Homey"
             }
         },
         {
             "name": "Attach to Homey",
             "type": "node",
             "request": "attach",
             "address": "myhomeyip",
             "port": 9222,
             "localRoot": "${workspaceFolder}",
             "remoteRoot": "/app/"
         }
     ]
 }

```

_(or variations for Cloud, different Homeys like above)_

1. Aplication app.js oninit update with (optional?) :

```auto
		if (process.env.DEBUG === '1') {
			require('inspector').open(9222, '0.0.0.0', true);
		}

```

_(or variations for Cloud, different Homeys like above)_

1. configure Chrome chrome://inspect/# to listen on myhomeyip:9222

2. run Launch APP in VSCODE via RUN - START DEBUGGING…  
 ![vscode](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/5/d53f3f341506afca4f6c61b1c62d4c4c03584901.png)  
(or start manually LAUNCH APP & Attach to Homey)

3. in Chrome launch /app//assets/app/bootstrap.mjs INSPECT - you shall see “Debugger attached” in VSCode as confirmation it’s connected

Inspector from my perspective just provide another view of what available already in VSCode but I’m sure someone more clever then me will comment on this.

And you must set Breakpoints to actually see anything and debug, also CALL STACK must be active on ATTACH TO HOMEY…

**If I missed anything or misunderstood anything, feel free to comment, I will then edit this post.**

_Note_

```auto
"localRoot": "${workspaceFolder}",

```

- seems it’s not required to be changed to `"localRoot": "${workspaceFolder}/.homeybuild"`, unless you run the code from .homeybuild (which I guess you should not)

---

<div class="post-metadata">

**Author:** ![Baschte](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Baschte](https://community.homey.app/u/Baschte)\
**Post date:** [February 9, 2025, 10:42am UTC](https://community.homey.app/t/debug-app-code/33516/38 "2025-02-09T10:42:52Z")

</div>

I had the problem that the debugger worked on my Homey Pro 2023 but the breakpoints didn’t work. The important note was above. I have to start everything in my VSCode via shell with `homey app run` myself and can then access this instance via the debugger on address 127.0.0.1 (not the homey ip). After that, everything works great. So I can’t start and use the Launch App command in the debugger. Thanks everyone for the help in this thread.

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [February 9, 2025, 2:13pm UTC](https://community.homey.app/t/debug-app-code/33516/39 "2025-02-09T14:13:56Z")

</div>

`homey app run` starts the app in Docker container (on your PC).  
If you want to run it on Homey directly, start is with `homey app run --remote` and use Homey-IP to connect the Debugger.

---

<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:** [February 9, 2025, 2:19pm UTC](https://community.homey.app/t/debug-app-code/33516/40 "2025-02-09T14:19:34Z")

</div>

> [@RonnyW](#):
>
> `homey app run` starts the app in Docker container (on your PC).

I only asked more than a year ago [to fix the documentation](https://apps.developer.homey.app/the-basics/getting-started/homey-cli#run-a-homey-app-in-development-mode) so it explains to add `--remote` to run the app code on Homey itself 🙄

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [February 9, 2025, 5:15pm UTC](https://community.homey.app/t/debug-app-code/33516/41 "2025-02-09T17:15:02Z")

</div>

Is there actually any benefit of running it on the docker instead of Homey itself?

[Previous page](https://community.homey.app/t/debug-app-code/33516.md?page=1)

[Next page](https://community.homey.app/t/debug-app-code/33516.md?page=3)
