# Npm package dependencies not found

**URL:** https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411
**Category:** Developing Nodes
**Created:** [10 April 2023 09:25 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411 "2023-04-10T09:25:06Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![hikuikuma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hikuikuma/32/78693_2.png) [@hikuikuma](https://discourse.nodered.org/u/hikuikuma)
#### Post date: [10 April 2023 09:25 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/1 "2023-04-10T09:25:06Z")

</div>

Hello, I'm trying to create nodes that connect to an API, I wanted to use fetch (node-fetch) which seems to me a simple solution to make requests to the API. But when I test my node, it sends me the error :

```auto
[ERR_MODULE_NOT_FOUND]: Cannot find package 'node-fetch' imported from <directory of node>

```

I did however declare it in my package.json :

```auto
"dependencies": {
    "node-fetch": "^2.6.9"
}

```

and I wanted to import it with this code placed at the first line of my .js document of the node :

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

```

Where did I make a mistake?  
Thanks

> Node-RED version : 3.0.2  
> Node.js version : v16.13.2  
> npm version : 9.6.4

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [10 April 2023 09:51 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/2 "2023-04-10T09:51:01Z")

</div>

Just a sanity check:

What does `npm ls node-fetch` show in your Node RED user Directory

---

<div class="post-metadata">

### Author: ![hikuikuma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hikuikuma/32/78693_2.png) [@hikuikuma](https://discourse.nodered.org/u/hikuikuma)
#### Post date: [10 April 2023 10:20 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/3 "2023-04-10T10:20:15Z")

</div>

Show this :

```auto
node-red-project@0.0.1 C:\Users\xxx\.node-red
`-- node-fetch@2.6.9

```

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [10 April 2023 10:38 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/4 "2023-04-10T10:38:59Z")

</div>

And your node is also installed in this location?  
Have you restarted Node RED after making changes to the code/package.json?  
ran `npm install`?

usually, it should show a hierarchy, similar to the below (I'm on a pi - so paths will differ)

```auto
root@raspberrypi:~/.node-red# npm ls node-fetch
node-red-project@0.0.1 /root/.node-red
└─┬ my-custom-node@8.0.0
  └── node-fetch@10.2.0

```

---

<div class="post-metadata">

### Author: ![hikuikuma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hikuikuma/32/78693_2.png) [@hikuikuma](https://discourse.nodered.org/u/hikuikuma)
#### Post date: [10 April 2023 10:42 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/5 "2023-04-10T10:42:23Z")

</div>

Yes, I have my custom node here and restart node-red after making changes and install my custom node and node-fetch.  
But I don't have a similar hierarchy...

```auto
node-red-project@0.0.1 C:\Users\xxx\.node-red
+-- @hikuikuma/node-red-contrib-twitch-api@0.0.1 -> .\D:\nodeRed\node-red-contrib-twitch-api
+-- @node-red-contrib-themes/theme-collection@3.0.6
`-- node-fetch@2.6.9

```

It's because work on Windows?

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [10 April 2023 10:54 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/6 "2023-04-10T10:54:58Z")

</div>

Ok - not sure what else to look at.

I don't do development on Windows for Node JS, plenty here who do though.

I don't think it should make any difference with using symlinks to your node - but then I don't know if windows has some quirks with relative paths 🤷‍♂️

i.e Windows is trying to locate it under  
`D:\nodeRed\node-red-contrib-twitch-api\node_modules\node-fetch` even though one exists in the Node RED home folder

Did you run `npm install` in  
`D:\nodeRed\node-red-contrib-twitch-api` or the `.node-red` directory - don't think it will make a difference to be honest 🤷‍♂️

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [10 April 2023 11:15 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/7 "2023-04-10T11:15:11Z")

</div>

I think that the problem here is that when running in a development mode, I don't think that your node module is checking what would normally be the "parent" folder, e.g. the Node-RED userDir.

For testing, make sure that you run `npm install` in the node package's folder and it should work. This sorts itself out when running in a more production mode where you've installed the node via [npmjs.org](http://npmjs.org) or GitHub.

Just make sure that you have a `.gitignore` file in your module folder that excludes `node_modules`.

---

<div class="post-metadata">

### Author: ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)
#### Post date: [10 April 2023 11:24 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/8 "2023-04-10T11:24:55Z")

</div>

I believe you can test this further.

in your js file at the top - print this out to console.  
`console.log(module.paths)`

You will get a print out similar to.  
this should show what paths the Node module will use to search for the module

```auto
[
  '/root/node_modules',
  '/node_modules',
  '/root/.node_modules',
  '/root/.node_libraries',
  '/usr/lib/node'
]

```

---

<div class="post-metadata">

### Author: ![hikuikuma](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hikuikuma/32/78693_2.png) [@hikuikuma](https://discourse.nodered.org/u/hikuikuma)
#### Post date: [10 April 2023 11:38 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/9 "2023-04-10T11:38:25Z")

</div>

> [@TotallyInformation](#):
>
> I think that the problem here is that when running in a development mode, I don't think that your node module is checking what would normally be the "parent" folder, e.g. the Node-RED userDir.

This is indeed the behavior to see, once the node-fetch package is installed in my package folder, it works very well!

> [@marcus-j-davies](#):
>
> this should show what paths the Node module will use to search for the module

In my case, this loads all the "node\_modules" folders from the node folder, up to the root of the disk which is my dev disk (D:) but my instance of Node RED is running on my main disk (C :), I think this explains it.

Infact when installing the package I'm developing with the path to the folder on D:\ disk, it create a symlink to this folder in the "node\_modules" folder of my Node RED instance, so it couldn't find "node-fetch" which was installed in this folder...

Thank you very much for your help, I will be able to continue my development and I hope to be able to offer a new package of nodes soon to the community!

---

<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: [24 April 2023 11:38 UTC](https://discourse.nodered.org/t/npm-package-dependencies-not-found/77411/10 "2023-04-24T11:38:29Z")

</div>

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