Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not handle ES modules #302

Open
1 task done
dathbe opened this issue May 16, 2024 · 0 comments
Open
1 task done

Does not handle ES modules #302

dathbe opened this issue May 16, 2024 · 0 comments

Comments

@dathbe
Copy link

dathbe commented May 16, 2024

OS

Raspbian 12

NodeJS Version

18.19.0

MagicMirror² Version

2.27.0

Remote Control Version

2.3.8

Did you try using just Remote Control alone with MM?

  • I have and the error still happening

Description

Remote-Control will not load ES Modules, and instead throws the following errors:

0|mm  | [2024-05-16 10:48:22.279] [ERROR] 2024-05-16T10:48:22 <error> ERROR! Could not load main module js file. Error found: Error [ERR_REQUIRE_ESM]: require() of ES Module /home/username/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js from /home/username/MagicMirror/modules/MMM-Remote-Control/node_helper.js not supported.
0|mm  | MMM-RAIN-MAP.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
0|mm  | Instead either rename MMM-RAIN-MAP.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/username/MagicMirror/modules/MMM-RAIN-MAP/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
0|mm  |  (/home/username/MagicMirror/modules/MMM-Remote-Control/node_helper.js:323 Class.loadModuleDefaultConfig)

Expected behavior

Either the module should use import() as suggested, or, if the module cannot handle ES Modules, it should check whether the module is an ES Module and not attempt to import it.

Current behavior

Log error as shown above.

Possible solution

?

Steps to reproduce

  1. Start MM with both MMM-remote-control and an ES Module module active.
  2. See error

Log

0|mm  | [2024-05-16 10:48:22.279] [ERROR] 2024-05-16T10:48:22 <error> ERROR! Could not load main module js file. Error found: Error [ERR_REQUIRE_ESM]: require() of ES Module /home/username/MagicMirror/modules/MMM-RAIN-MAP/MMM-RAIN-MAP.js from /home/username/MagicMirror/modules/MMM-Remote-Control/node_helper.js not supported.
0|mm  | MMM-RAIN-MAP.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
0|mm  | Instead either rename MMM-RAIN-MAP.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/username/MagicMirror/modules/MMM-RAIN-MAP/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
0|mm  |  (/home/username/MagicMirror/modules/MMM-Remote-Control/node_helper.js:323 Class.loadModuleDefaultConfig)

config.js

n/a

Additional info

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant