# Can't find module after install (any module)

**URL:** <https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338>\
**Category:** General\
**Created:** [6 February 2020 08:58 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338 "2020-02-06T08:58:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![landown](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@landown](https://discourse.nodered.org/u/landown)\
**Post date:** [6 February 2020 08:58 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/1 "2020-02-06T08:58:49Z")

</div>

Hi!

I'm developing a project in which I got Node-RED embedded inside Node.js, so Node-RED starts up when I start the Node.js server.

The Node-RED dir has its own package.json. The directory structure is the following:  
asd

```auto
.
├── .nodered/
│ └── package.json 
│ └── node-red-contrib-s7/ (or any other module)
│ 
└── package.json
     └── node-red/

```

The problem happens with any module, not only with 'node-red-contrib-s7'. So the problem is, when I install a package from terminal (being inside .nodered/) with 'npm install whatever', apparently it installs correctly, but updating Node-RED does not show the new modules, and I can't see them inside the Pallete Manager. If I search for them in the Install tabs inside the Pallete Manager, they show as not installed. If I press install, they following message appears:

Failed to install: node-red-contrib-s7

Cannot find module 'node-red-contrib-s7'

Check the log for more information

The weird thing is that the packages ARE in the package.json (in the one inside .nodered/ ), so they've been correctly installed. I also tried this last step (installing from Pallete manager) after uninstalling the module from .package.json, and didn't work. Also, if I go to the log in the Palette Manager, it does not show any error, it installs the package correctly:

```auto
2020-02-06T08:47:32.344Z npm install --no-audit --no-update-notifier --save --save-prefix="~" --production node-red-contrib-s7@2.1.1
2020-02-06T08:47:34.821Z [out] 
2020-02-06T08:47:34.821Z [out] > usb@1.6.2 install /Users/javier.marzan/tfg/back/.nodered/node_modules/usb
2020-02-06T08:47:34.821Z [out] > prebuild-install --verbose || node-gyp rebuild
2020-02-06T08:47:34.821Z [out] 
2020-02-06T08:47:34.996Z [err] prebuild-install
2020-02-06T08:47:34.997Z [err]  
2020-02-06T08:47:34.997Z [err] info begin
2020-02-06T08:47:34.997Z [err] Prebuild-install version 5.3.3
2020-02-06T08:47:35.000Z [err] prebuild-install 
2020-02-06T08:47:35.000Z [err] info looking for cached prebuild @ /Users/javier.marzan/.npm/_prebuilds/73a0d1-usb-v1.6.2-node-v64-darwin-x64.tar.gz
2020-02-06T08:47:35.001Z [err] prebuild-install 
2020-02-06T08:47:35.001Z [err] info found cached prebuild 
2020-02-06T08:47:35.001Z [err] prebuild-install info
2020-02-06T08:47:35.001Z [err] unpacking @ /Users/javier.marzan/.npm/_prebuilds/73a0d1-usb-v1.6.2-node-v64-darwin-x64.tar.gz
2020-02-06T08:47:35.020Z [err] prebuild-install 
2020-02-06T08:47:35.020Z [err] info unpack resolved to /Users/javier.marzan/tfg/back/.nodered/node_modules/usb/build/Release/usb_bindings.node
2020-02-06T08:47:35.027Z [err] prebuild-install
2020-02-06T08:47:35.027Z [err] info unpack required /Users/javier.marzan/tfg/back/.nodered/node_modules/usb/build/Release/usb_bindings.node successfully
2020-02-06T08:47:35.027Z [err] prebuild-install
2020-02-06T08:47:35.027Z [err] info install Successfully installed prebuilt binary!
2020-02-06T08:47:35.129Z [out] + node-red-contrib-s7@2.1.1
2020-02-06T08:47:35.129Z [out] added 64 packages from 46 contributors in 2.2s
2020-02-06T08:47:35.153Z rc=0

```

And everytime, package is correctly shown inside package.json. This leads me to think that in some way, Node-RED is not pointing to the correct directory for modules, which is weird because I didn't manually change anything in the direct structure that Node-RED created. I also tried to install the packages in the other package.json just in case, and it didn't work either. I didn't find any setting for changing where Node-RED searches for modules.

So I'm a bit lost right now. Any help? Thanks in advance!

---

<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:** [6 February 2020 09:39 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/2 "2020-02-06T09:39:54Z")

</div>

Can you show the startup log for Node-RED please? That should tell us where it is looking for its settings.js and userDir folders and that should make things clearer.

---

<div class="post-metadata">

**Author:** ![landown](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@landown](https://discourse.nodered.org/u/landown)\
**Post date:** [6 February 2020 10:34 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/3 "2020-02-06T10:34:04Z")

</div>

```auto
Welcome to Node-RED
===================

6 Feb 09:47:15 - [info] Node-RED version: v1.0.3-git
6 Feb 09:47:15 - [info] Node.js version: v10.16.0
6 Feb 09:47:15 - [info] Darwin 18.7.0 x64 LE
6 Feb 09:47:16 - [info] Loading palette nodes
6 Feb 09:47:16 - [info] Context store : 'default' [module=memory]
6 Feb 09:47:16 - [info] User directory : ./.nodered
6 Feb 09:47:16 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
6 Feb 09:47:16 - [info] Flows file : /Users/javier.marzan/tfg/back/flows.json
6 Feb 09:47:16 - [info] Starting flows
6 Feb 09:47:16 - [info] Started flows

```

And actually, I also saw this in the same logs:

```auto
6 Feb 09:47:32 - [info] Installing module: node-red-contrib-s7, version: 2.1.1
6 Feb 09:47:35 - [info] Installed module: node-red-contrib-s7

```

It's weird because it seems to know where to install them, but not were to look for them (?)

---

<div class="post-metadata">

**Author:** ![landown](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@landown](https://discourse.nodered.org/u/landown)\
**Post date:** [10 February 2020 13:34 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/4 "2020-02-10T13:34:16Z")

</div>

Any ideas? I already posted the logs 🙂

---

<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 February 2020 17:31 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/5 "2020-02-10T17:31:01Z")

</div>

So your userDir is `./.nodered` and the flows file is in `/Users/javier.marzan/tfg/back` normally, the flows file would be in the userDir.

Your folder/file structure should look something like this:

```auto
<NodeJS_Project_Folder>
├── .nodered/
│ ├── package.json (nodes listed here normally but could be in master instead)
│ ├── flows.json (and similar files like creds, etc.)
│ └── node_modules
│ └── node-red-contrib-s7/ (or any other module)
│ 
├── package.json (generally no nodes listed though they can be)
│ (will contain dependencies for ExpressJS, 
│ `main` should be set to startup js file)
└── node_modules
       ├── @node-red
       ├── expressjs
       └── node-red

```

And your startup js file should have something like this either in it or required to it:

```auto
const http = use_https ? require("https") : require("http");

const express = require("express"); // THE std library for serving HTTP
const RED = require("node-red");
var nrSettings = require("./settings.js"); // Node-Red settings file
const fs = require("fs");

...

const express = require("express"); // THE std library for serving HTTP
const RED = require("node-red");
var nrSettings = require("./settings.js"); // Node-Red settings file
const fs = require("fs");

....

// Create an Express app
var app = express();

...

// Initialise the runtime with a server and settings
// @see http://nodered.org/docs/configuration.html
RED.init(httpServer, nrSettings);

// Serve the editor UI from /admin
app.use(nrSettings.httpAdminRoot, RED.httpAdmin);

// Serve the http nodes from /
app.use(nrSettings.httpNodeRoot, RED.httpNode);

httpServer.listen(http_port, listening_address, function() {
  console.info(
    "Express 4 https server listening on http%s://%s:%d%s, serving node-red",
    use_https ? "s" : "",
    httpServer.address().address.replace("0.0.0.0", "localhost"),
    httpServer.address().port,
    nrSettings.httpAdminRoot
  );
});

// Start the runtime
RED.start();

```

That code is a bit old but I think it is still roughly correct.

> <https://github.com/TotallyInformation/node-red-template-embedded/blob/master/server.js>

Does that help at all? I think that however you are starting up NR, you've not quite got all of your settings aligned.

Next step would be for you to share your settings.js file or whatever you are using instead of that.

---

<div class="post-metadata">

**Author:** ![landown](https://avatars.discourse-cdn.com/v4/letter/l/f475e1/32.png) [@landown](https://discourse.nodered.org/u/landown)\
**Post date:** [10 February 2020 19:04 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/7 "2020-02-10T19:04:18Z")

</div>

Ok, I finally got it working.. !

I realised while going over `settings.js` again that I could change the detail of logging output, so I changed that to **trace** and saw the following:

```auto
10 Feb 19:51:31 - [debug] Module: node-red-node-rbe 0.2.8
10 Feb 19:51:31 - [debug] /Users/javier.marzan/tfg/back/node_modules/node-red-node-rbe
10 Feb 19:51:31 - [debug] Module: node-red-node-tail 0.0.3
10 Feb 19:51:31 - [debug] /Users/javier.marzan/tfg/back/node_modules/node-red-node-tail

```

It looked really weird to me, as I had already tried installing modules in root and hadn't worked (`back` is my project root dir). But I gave it a try, reset everything after that... and I finally had my nodes! Dunno what changed...  
Anyway, as of my files structure and `flows.json` , I now have a **node-red** project, and everything is located in there (except apparently the nodes), so its better organised.

Thanks for all the help and your time, really.  
Have a nice week!

---

<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 February 2020 19:04 UTC](https://discourse.nodered.org/t/cant-find-module-after-install-any-module/21338/8 "2020-02-24T19:04:24Z")

</div>

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