# Node-Fetch needs import on debug but does not work on production

**URL:** <https://community.homey.app/t/node-fetch-needs-import-on-debug-but-does-not-work-on-production/102057>\
**Category:** Developers\
**Tags:** homey-pro, community-app\
**Created:** [January 23, 2024, 10:23am UTC](https://community.homey.app/t/node-fetch-needs-import-on-debug-but-does-not-work-on-production/102057 "2024-01-23T10:23:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanneskl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hanneskl/32/80114_2.png) [@hanneskl](https://community.homey.app/u/hanneskl)\
**Post date:** [January 23, 2024, 10:23am UTC](https://community.homey.app/t/node-fetch-needs-import-on-debug-but-does-not-work-on-production/102057/1 "2024-01-23T10:23:57Z")

</div>

I am using, node-fetch to query my devices on the device.js  
On debug, I need to import  
`const fetch = require('node-fetch');`  
Without it, I get this error when running `homey app run`:

```auto
[ManagerDrivers] [Driver:solarpanel] [Device:09843584-dbce-45d8-bd3d-22068247553a] Error: ReferenceError: fetch is not defined
    at SolarPanel.pullData (/app/drivers/solarpanel/device.js:26:7)

```

However, leaving the line in on production (deploying via `homey app install`), breaks the app. I get this error both in the developer tools and homeyscript:

```auto
Could not get device by ID.

```

Leaving that line out works fine in production for some reason.

---

<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:** [January 23, 2024, 11:26am UTC](https://community.homey.app/t/node-fetch-needs-import-on-debug-but-does-not-work-on-production/102057/2 "2024-01-23T11:26:18Z")

</div>

~~What does “on debug” mean? Do you mean `homey app run` or `homey app run --remote`? (and if so, which one specifically?) Which Homey model?~~

Okay, I see the issue:

- HP2023, `homey app run --remote`: `fetch` is defined (probably built into Node)
- HP2023, `homey app run`: `fetch` is not defined
- Older HP’s: `fetch` is not defined

So if you really want to use `fetch`, the best way is to ship your app with `node-fetch` as a dependency.

I think the error (“Could not get device by ID”) is unrelated.

---

<div class="post-metadata">

**Author:** ![hanneskl](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/hanneskl/32/80114_2.png) [@hanneskl](https://community.homey.app/u/hanneskl)\
**Post date:** [January 23, 2024, 12:21pm UTC](https://community.homey.app/t/node-fetch-needs-import-on-debug-but-does-not-work-on-production/102057/3 "2024-01-23T12:21:46Z")

</div>

> So if you really want to use `fetch` ,  
> Do you have an alternative in mind?

---

<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:** [January 23, 2024, 12:36pm UTC](https://community.homey.app/t/node-fetch-needs-import-on-debug-but-does-not-work-on-production/102057/4 "2024-01-23T12:36:02Z")

</div>

For Homeyscript, all you have available is `fetch`, for apps you can use something like [`http.min`](https://www.npmjs.com/package/http.min), but it depends on your specific requirements.
