Read the statement by Michael Teeuw here.
node_helper.js is not working?
-
Hello all,
Background:
I am writing this post today about the issues I have been having with all modules involving node_helper.js. To start from the beginning, I recently started a MM project as I had all the parts needed lying around. I flashed the SD to Raspbian GNU/Linux 11 (bullseye) on my Raspberry Pi 3B.I have successfully installed all default modules and they all work great with no issues. I have also installed MMM-JokeAPI (a module that doesn’t use node_helper.js) and it works fine. It just uses the main module js file and fetches the data in there.
The issue:
I have noticed a strange pattern that seems to be emerging with any modules using node_helper.js. As I speak of these issues, here are the modules that I have tested all having this issue: (MMM-Cocktails, MMM-Dad-Jokes, MMM-DynamicWeather, MMM-RandomQuotes).**Another note, I know these modules may be “depreciated”, but many of them are very simple. Its just an API request basically. I have looked diligently through all of these for hours and don’t see a reason for the following issues. I have tested all of these API endpoints and the way they parse them. (They all still work)
First, no matter if I include
const Log = require("logger");
at the top of a node_helper.js file, I am unable to recieve output from Log.info, Log.log, Log.error or even console.log. I have looked at many forums on this issue, for many looking in the right location fixed this. I have restarted my MM hundreds of times looking at developer tools, the console and using pm2 logs and haven’t seen 1 output from these files. (This really sucks because I cant debug!) For example:module.exports = NodeHelper.create({ Log.info("Testing this helper"); console.log("TESTING this helper"); start: function() { console.log("Starting node_helper for: " + this.name); Log.info("Starting node helper") },
I have tried sending console output in all of these modules in every location you can think of. I first thought that somehow the logs aren’t reaching the terminal console or the dev tools console, but now, I think these files may not be running at all.
So to test this, in every single one of these modules, I went to the main module class. I found where
sendSocketNotification(notification, payload)
was used and did a Log.info(“Sending notification for XYZ module”). (Note, Logging always worked in the main module classes). For every single one of these modules, I got a log showing this bit of code was run.Now, I went to the spot in the modules main js files where
socketNotificationReceived: function(notification, payload) {}
was ran, and put a Log.info(“Recieved notification”) inside the function. None of the modules outputted this log. This is now why I am writing this post, because I am completely lost on what could be going on.I even just recently tested MMM-RandomQuotes, which just had a github update 5 days ago (presumably works) but I had the same outcome here.
If curious, what these modules look like when starting MM, is their “loading” icons or “loading” text that appears since the API data does not seem to be coming back.
Even with my hours of studying these files and doing research, I will say I’m still very much a beginner to the MagicMirror ins and outs. I would really appreciate any help on this, as I am currently unable to add anything it seems containing a node_helper.js class. Please let me know anything I can provide to help if needed. Thanks! :)
-
@vandy2424 ok, got it…
the last line of the model (sample) config.js is critical
/*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { module.exports = config; }
because it was NOT there in yours,
when we loaded the config using require()
it returned {} (nothing)
and the default was used, this is why no error was shown…file existed, was loaded successfully, but had no data
my install script copies the config.js.sample to config.js so users most likely woudn’t experience this
-
@vandy2424 what version of MagicMirror are you using?
what version of nodejs and electron are you running
if you do npm run server do you get messages?
-
@sdetweil Hi Sam, thank you for the quick reply!
MagicMirror version: v2.26.0
NodeJs version: v20.11.0
Electron version: 27.2.0If I do npm run server I do not get the messages.
-
@vandy2424
Is there any suspicious log in your terminal and front dev-console both? What they said? -
@MMRIZE Hello. To simplify this output, I am just enabling the default clock and weather module and MMM-DynamicWeather for these outputs. First is the dev console output. There is a Electron Security Warning but I think thats just a security notice. At the bottom, there is also another warning regarding the WebSocket.
Dev-Console:
main.js:589 Initializing MagicMirror². translator.js:122 Loading core translation file: translations/en.json VM4 sandbox_bundle:2 Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security Policy set or a policy with "unsafe-eval" enabled. This exposes users of this app to unnecessary security risks. For more information and help, consult https://electronjs.org/docs/tutorial/security. This warning will not show up once the app is packaged. warnAboutInsecureCSP @ VM4 sandbox_bundle:2 translator.js:138 Loading core translation fallback file: translations/en.json loader.js:165 Load script: modules/default/clock/clock.js module.js:484 Module registered: clock loader.js:138 Bootstrapping module: clock loader.js:165 Load script: vendor/node_modules/moment/min/moment-with-locales.js loader.js:165 Load script: vendor/node_modules/moment-timezone/builds/moment-timezone-with-data.js loader.js:165 Load script: vendor/node_modules/suncalc/suncalc.js loader.js:142 Scripts loaded for: clock loader.js:180 Load stylesheet: modules/default/clock/clock_styles.css loader.js:145 Styles loaded for: clock loader.js:148 Translations loaded for: clock loader.js:165 Load script: modules/default/weather/weather.js module.js:484 Module registered: weather loader.js:138 Bootstrapping module: weather loader.js:237 File already loaded: moment.js loader.js:165 Load script: modules/default/weather/weatherutils.js loader.js:165 Load script: modules/default/weather/weatherobject.js loader.js:165 Load script: modules/default/weather/providers/overrideWrapper.js loader.js:165 Load script: modules/default/weather/weatherprovider.js loader.js:237 File already loaded: suncalc.js loader.js:165 Load script: modules/default/weather/providers/openweathermap.js loader.js:142 Scripts loaded for: weather loader.js:180 Load stylesheet: vendor/css/font-awesome.css loader.js:180 Load stylesheet: vendor/node_modules/weathericons/css/weather-icons.css loader.js:180 Load stylesheet: modules/default/weather/weather.css loader.js:145 Styles loaded for: weather loader.js:148 Translations loaded for: weather loader.js:138 Bootstrapping module: weather loader.js:237 File already loaded: moment.js loader.js:237 File already loaded: weatherutils.js loader.js:237 File already loaded: weatherobject.js loader.js:237 File already loaded: modules/default/weather/providers/overrideWrapper.js loader.js:237 File already loaded: weatherprovider.js loader.js:237 File already loaded: suncalc.js loader.js:237 File already loaded: modules/default/weather/providers/openweathermap.js loader.js:142 Scripts loaded for: weather loader.js:237 File already loaded: font-awesome.css loader.js:237 File already loaded: weather-icons.css loader.js:237 File already loaded: weather.css loader.js:145 Styles loaded for: weather loader.js:148 Translations loaded for: weather loader.js:165 Load script: modules/MMM-DynamicWeather/MMM-DynamicWeather.js module.js:484 Module registered: MMM-DynamicWeather loader.js:138 Bootstrapping module: MMM-DynamicWeather loader.js:142 Scripts loaded for: MMM-DynamicWeather loader.js:180 Load stylesheet: modules/MMM-DynamicWeather/MMM-DynamicWeather.css loader.js:145 Styles loaded for: MMM-DynamicWeather loader.js:148 Translations loaded for: MMM-DynamicWeather loader.js:180 Load stylesheet: css/custom.css clock.js:49 Starting module: clock weatherprovider.js:35 Weather provider: OpenWeatherMap initialized. weatherprovider.js:46 Weather provider: OpenWeatherMap started. weatherprovider.js:35 Weather provider: OpenWeatherMap initialized. weatherprovider.js:46 Weather provider: OpenWeatherMap started. MMM-DynamicWeather.js:94 Starting MMM-DynamicWeather MMM-DynamicWeather.js:111 https://api.openweathermap.org/data/3.0/onecall?appid=51acaf6aca47c36542b28b6342d4714a&lat=41.75&lon=-88.16 MMM-DynamicWeather.js:227 Checked dates MMM-DynamicWeather.js:165 [MMM-DynamicWeather] Finished initialization main.js:608 All modules started! websocket.js:121 WebSocket connection to 'ws://localhost:8080/socket.io/?EIO=4&transport=websocket&sid=-Su8ujYWaq21RNXeAAAA' failed: WebSocket is closed before the connection is established. doClose @ websocket.js:121 weather.js:166 New weather information available. weather.js:166 New weather information available. clock.js:67 [Violation] 'setTimeout' handler took 147ms
For the terminal, everything is good besides a warning regarding vkCreateInstance drivers. I didn’t think to mention these warnings as my default modules are still working perfectly fine and the ones with node_helper.js that aren’t working, are still displaying their DIV on the MagicMirror (“…loading”).
Terminal:
[09.02.2024 12:30.48.203] [LOG] Starting MagicMirror: v2.26.0 [09.02.2024 12:30.48.214] [LOG] Loading config ... [09.02.2024 12:30.48.220] [DEBUG] config template file not exists, no envsubst [09.02.2024 12:30.48.227] [LOG] Loading module helpers ... [09.02.2024 12:30.48.283] [LOG] Initializing new module helper ... [09.02.2024 12:30.48.285] [LOG] Module helper loaded: updatenotification [09.02.2024 12:30.48.287] [LOG] No helper found for module: helloworld. [09.02.2024 12:30.48.289] [LOG] All module helpers loaded. [09.02.2024 12:30.48.307] [LOG] Starting server on port 8080 ... [09.02.2024 12:30.48.778] [LOG] Server started ... [09.02.2024 12:30.48.781] [LOG] Connecting socket for: updatenotification [09.02.2024 12:30.48.783] [LOG] Starting module helper: updatenotification [09.02.2024 12:30.48.784] [LOG] Sockets connected & modules started ... [09.02.2024 12:30.48.808] [LOG] Launching application. Warning: vkCreateInstance: Found no drivers! Warning: vkCreateInstance failed with VK_ERROR_INCOMPATIBLE_DRIVER at CheckVkSuccessImpl (../../third_party/dawn/src/dawn/native/vulkan/VulkanError.cpp:88) at CreateVkInstance (../../third_party/dawn/src/dawn/native/vulkan/BackendVk.cpp:458) at Initialize (../../third_party/dawn/src/dawn/native/vulkan/BackendVk.cpp:344) at Create (../../third_party/dawn/src/dawn/native/vulkan/BackendVk.cpp:266) at operator() (../../third_party/dawn/src/dawn/native/vulkan/BackendVk.cpp:521)
Again my knowledge of js and web applications is very limited so these warnings may have something to do with this node_helper issue that I’m unaware of. Please let me know if there is any other information that is useful.
Thanks!
-
@vandy2424 we need to see the matching config.js please.
this run says only hello world and updatenotification are enabled
-
@vandy2424
If websocket is closed, the path between module and node_helper might be broken. May that be the reason or clue. But very unusual thing. ATM I cannot guess what happened. -
@vandy2424 said in node_helper.js is not working?:
To simplify this output, I am just enabling the default clock and weather module and MMM-DynamicWeather for these outputs
nothing matches that. please show the config.js and the logs from both backend and front end
-
@sdetweil Hi Sam, I am not sure what you mean by showing the logs from the backend and front end. I thought that is what I just showed you. (Terminal & dev console). You can see in the dev console, it loading clock, weather and MMM-DynamicWeather modules.
Please let me know what I am not understanding here and I will get you those logs. Thanks!
Here is the config.js file:
let config = { address: "0.0.0.0", // default is "localhost", port: 8080, // default, ipWhitelist: [], // default -- need to add your IP here, modules: [ { module: "clock", position: "top_left", config: { timeFormat:12, timezone:"America/Chicago", displaySeconds:"true", showPeriod:"true", showDate:"true", displayType:"both", }, }, { module: "weather", position: "top_right", config: { type: "current", units: "imperial", tempUnits: "imperial", windUnits: "imperial", apiVersion: "3.0", weatherEndpoint: "/onecall", apiKey: "KEY", lat:"50.75", lon:"-88.16", showUVindex:"true", }, }, { module: "weather", position: "top_right", config: { type: "daily", units: "imperial", tempUnits: "imperial", windUnits: "imperial", apiVersion: "3.0", weatherEndpoint: "/onecall", apiKey: "KEY", lat:"50.75", lon:"-88.16", }, }, { module: 'MMM-DynamicWeather', position: 'fullscreen_above', config: { // See https://github.com/scottcl88/MMM-DynamicWeather for more information. api_key: "KEY", lat:"50", lon:"-88.16", }, }, ], };
Again this is just with the DynamicWeather module. I can add others but this simplifies.
-
@vandy2424 backend , console output from npm start
front end, in the developers window
this config does not match the messages