kolbyjack / MMM-Wallpaper

MagicMirror module to display wallpapers from various online sources
https://magicmirror.builders/
MIT License
99 stars 31 forks source link

TypeError: fetch is not a function #97

Closed Robert-litts closed 8 months ago

Robert-litts commented 9 months ago

Good Morning,

First, I've been running MagicMirror with MMM-Wallpaper for years, for the most part flawlessly. Thanks for all of the modules you maintain!

Last night, I upgraded my MagicMirror to 2.25 and at the same time, had to upgrade my node from v16 to v20. After the upgrade, my mirror was unable to start and threw the following error:

 unhandled promise rejection warning: cannot find module 'fetch'
Require stack:
- /home/orangepi/MagicMirror/modules/MMM-Wallpaper/node_helper.js

Commenting MMM-Wallpaper out from config.js allowed the mirror to start. I then went into MagicMirror main directory and ran "npm install fetch", which ran fine. I then un-commented MMM-Wallpaper from my config and was able to run and start my mirror fine, but had no wallpaper showing up.

Reviewing my logs, I am now receiving the following errors:

0|mm  | [02.10.2023 06:14.47.203] [ERROR] Whoops! There was an uncaught exception...
0|mm  | [02.10.2023 06:14.47.242] [ERROR] TypeError: fetch is not a function
0|mm  |     at Class.request (/home/orangepi/MagicMirror/modules/MMM-Wallpaper/node_helper.js:232:5)
0|mm  |     at Class.fetchWallpapers (/home/orangepi/MagicMirror/modules/MMM-Wallpaper/node_helper.js:172:12)
0|mm  |     at Class.socketNotificationReceived (/home/orangepi/MagicMirror/modules/MMM-Wallpaper/node_helper.js:68:12)
0|mm  |     at Socket.<anonymous> (/home/orangepi/MagicMirror/js/node_helper.js:104:11)
0|mm  |     at Socket.emit (node:events:513:28)
0|mm  |     at Socket.emitUntyped (/home/orangepi/MagicMirror/node_modules/socket.io/dist/typed-events.js:69:22)
0|mm  |     at /home/orangepi/MagicMirror/node_modules/socket.io/dist/socket.js:704:39
0|mm  |     at processTicksAndRejections (node:internal/process/task_queues:77:11)
0|mm  | [02.10.2023 06:14.47.245] [ERROR] MagicMirror² will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
0|mm  | [02.10.2023 06:14.47.248] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues

Do you think this is an error with MMM-Wallpaper or with MagicMirror itself? I noticed that the release notes stated: "Replace node-fetch with internal fetch (https://github.com/MichMich/MagicMirror/issues/2649) and remove digest-fetch", so not sure if that is related. However, the fact that I had to manually install 'fetch'

Thank you!

apiontek commented 9 months ago

I just encountered the same issue. The solution for me was to comment out line 11 in node_helper.js

// const fetch = require("fetch");

I only use local files myself but I tested switching to using "bing" and it gave me fetched wallpaper, so I think this could be a complete fix.

Robert-litts commented 9 months ago

@apiontek This worked for me! Also I just pulled down the latest commit fixed the issue officially.

@kolbyjack as I stated above, this appears to be solved for me with you action. Thanks so much for the quick response and assistance!