runnane / node-red-contrib-easee

Node-Red module for streaming Easee charger data.
Apache License 2.0
7 stars 4 forks source link

ERR_REQUIRE_ESM when installing node. #1

Closed joli530 closed 1 year ago

joli530 commented 1 year ago

Cannot install module on: Node-RED version: v3.0.2 Node.js version: v16.16.0 Linux 5.15.32-v7 arm LE Got the following errors:

[@runnane/node-red-contrib-easee/easee-configuration] Error [ERR_REQUIRE_ESM]: require() of ES Module /config/node-red/node_modules/node-fetch/src/index.js from /config/node-red/node_modules/@runnane/node-red-contrib-easee/easee-client/easee-configuration.js not supported. Instead change the require of index.js in /config/node-red/node_modules/@runnane/node-red-contrib-easee/easee-client/easee-configuration.js to a dynamic import() which is available in all CommonJS modules. 10 Sep 15:27:33 - [warn] [@runnane/node-red-contrib-easee/easee-rest-client] Error [ERR_REQUIRE_ESM]: require() of ES Module /config/node-red/node_modules/node-fetch/src/index.js from /config/node-red/node_modules/@runnane/node-red-contrib-easee/easee-client/easee-rest-client.js not supported. Instead change the require of index.js in /config/node-red/node_modules/@runnane/node-red-contrib-easee/easee-client/easee-rest-client.js to a dynamic import() which is available in all CommonJS modules. 10 Sep 15:27:33 - [warn] [@runnane/node-red-contrib-easee/charger-streaming-client] Error [ERR_REQUIRE_ESM]: require() of ES Module /config/node-red/node_modules/node-fetch/src/index.js from /config/node-red/node_modules/@runnane/node-red-contrib-easee/easee-client/charger-streaming-client.js not supported. Instead change the require of index.js in /config/node-red/node_modules/@runnane/node-red-contrib-easee/easee-client/charger-streaming-client.js to a dynamic import() which is available in all CommonJS modules.

joli530 commented 1 year ago

I was able to install by replacing the require statement with

const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));

runnane commented 1 year ago

Hi Johan. Thank you for reporting. I have updated the package with your suggested fix. https://www.npmjs.com/package/@runnane/node-red-contrib-easee