# Issue with external module

**URL:** https://discourse.nodered.org/t/issue-with-external-module/50500
**Category:** General
**Created:** [1 September 2021 12:08 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500 "2021-09-01T12:08:13Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:08 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/1 "2021-09-01T12:08:14Z")

</div>

Hi averyone. Need help. I got the issue in Node-red

````auto
require() of ES modules is not supported.
require() of /home/ubuntu/scalar-crm-integration/externalModules/node_modules/node-fetch/src/index.js from /usr/lib/node_modules/node-red/node_modules/@node-red/registry/lib/externalModules.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/ubuntu/scalar-crm-integration/externalModules/node_modules/node-fetch/package.json.```
````

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 September 2021 12:25 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/2 "2021-09-01T12:25:52Z")

</div>

Hi @Tonna100

please share some details on what you are trying to do, where you see that message and what it is related to.

---

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:37 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/3 "2021-09-01T12:37:13Z")

</div>

My node-red application hosted on AWS Linux server and managed by pm2. I try to export external modules to function node like moment or node-fetch and get thise issue. But I have not any troubles on my local machine

"Error: Function node failed to load external modules"

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 September 2021 12:37 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/4 "2021-09-01T12:37:56Z")

</div>

What version of node.js are you using on the server?

---

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:38 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/5 "2021-09-01T12:38:36Z")

</div>

Node - v14.17.0

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 September 2021 12:39 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/6 "2021-09-01T12:39:16Z")

</div>

Where are you seeing that message exactly?

How are you trying to use the externalModules option?

---

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:41 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/7 "2021-09-01T12:41:13Z")

</div>

![2021-09-01_154117](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e83e701bdcbaf20308a8364d8f6c030ea8ef4faf.jpeg)

 ![2021-09-01_154130](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/84d0f5f1e271852dd3cdb388f81eebea77189110.jpeg)

Code example:

```auto
const getResourse = async (url, headers, retries = 3) => {
     const response = await fetch(url, headers);
    if (response.status !== 200) {
         if (retries > 0) {
             return getResourse(url, headers, retries - 1);
         } else {
             return {'statusCode':response.status, 'message':response.statusText};
         }
    }
   return await response.json();
}

```

On the local machine thise code works

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 September 2021 12:42 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/8 "2021-09-01T12:42:48Z")

</div>

What version of Node-RED have you got on the server?

---

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:43 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/9 "2021-09-01T12:43:28Z")

</div>

Node-red v.1.3.5

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 September 2021 12:44 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/10 "2021-09-01T12:44:28Z")

</div>

To use ESM modules with Node-RED you'll need Node-RED 2.x.

---

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:46 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/11 "2021-09-01T12:46:19Z")

</div>

Ok. But I have node-red the same version on my local machine and it works fine

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [1 September 2021 12:48 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/12 "2021-09-01T12:48:55Z")

</div>

Check to see if you have the same version of `node-fetch` installed in both places. Perhaps you have an older version locally that can be required, rather than imported.

The fact remains, Node-RED wasn't updated to use `import` for external modules until 2.x.

---

<div class="post-metadata">

### Author: ![Tonna100](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tonna100/32/34860_2.png) [@Tonna100](https://discourse.nodered.org/u/Tonna100)
#### Post date: [1 September 2021 12:58 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/13 "2021-09-01T12:58:57Z")

</div>

Thank you for your help. I will try to update Node-red application to 2.x version

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [31 October 2021 12:59 UTC](https://discourse.nodered.org/t/issue-with-external-module/50500/14 "2021-10-31T12:59:48Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
