Jopyth/MMM-Remote-Control

node_helper tries to validate client JavaScript out browser context

jalibu opened this issue · 0 comments

OS

any

NodeJS Version

14.17.x

MagicMirror Version

2.16.0

Remote Control Version

2.3.6

Did you try using just Remote Control alone with MM?

  • I have and the error still happening

Description

In the node_helper's loadModuleDefaultConfig() function is a require statement, which loads each module's main JavaScript file.
As these JavaScript files are executed in the browser, they may contain global variables such as "window". As this does not exist in the Node.js context, this module prints a ReferenceError.

I'd recommend to reduce the severity of the catched Error message to INFO or WARN (not ERROR), as it does not effect runtime stability.
Please also consider to find another, more robust way to parse MM modules.

Expected behavior

Appropriate severity logging
No parser errors on require()

Current behavior

see above

Possible solution

No response

Steps to reproduce

  1. Install MMM-RAIN-MAP (or any other module that references browser objects) next to MMM-Remote-Control
  2. Start MagicMirror
  3. Check logs

Log

[30.08.2021 22:25.33.102] [ERROR] ERROR! Could not validate main module js file.
[30.08.2021 22:25.33.106] [ERROR] ReferenceError: window is not defined
    at eval (webpack://mmm-rain-map/./node_modules/leaflet/dist/leaflet-src.js?:226:19)
    at eval (webpack://mmm-rain-map/./node_modules/leaflet/dist/leaflet-src.js?:7:11)
    at eval (webpack://mmm-rain-map/./node_modules/leaflet/dist/leaflet-src.js?:9:2)
    at Object../node_modules/leaflet/dist/leaflet-src.js (/Users/me/git/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:1:119)
    at __webpack_require__ (/Users/me/git/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:1:488355)
    at eval (webpack://mmm-rain-map/./src/client/Client.ts?:12:11)
    at Object../src/client/Client.ts (/Users/me/git/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:1:471167)
    at __webpack_require__ (/Users/me/git/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:1:488355)
    at /Users/me/git/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:1:488437
    at Object.<anonymous> (/Users/me/git/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js:1:488484)

config.js

modules: [
 {
  module: "MMM-RAIN-MAP",
  position: "bottom_center"
 },
 {
  module: "MMM-Remote-Control",
  position: "bottom_left",
  disabled: false,
  config: {
   customCommand: {},
   customMenu: "custom_menu.json",
   showModuleApiMenu: true
  }
 }
]

Additional info

No response