Sergey Panfilov Sergey Panfilov - 2 years ago 77
Node.js Question

Foreverjs tries to find module in /node_modules/my-module/node_modules/my-module

I use foreverjs to start my services. Also I use nodejs v5 with nvm. Running on mac.

Everything working fine yesterday, but today (after

npm update
) I suddenly have an errors like
when I'm try to
npm start

The project structure is:


Config for foreverjs (

"append": true,
"uid": "my-service-one",
"script": "index.js",
"sourceDir": "node_modules/my-service-one"
"append": true,
"uid": "my-service-two",
"script": "index.js",
"sourceDir": "node_modules/my-service-two"

And I launch it with npm start(

"scripts": {
"start": "node_modules/forever/bin/forever start services.json",

But when I try to make
npm start
, I have an error:

Error: Cannot find module '/Users/my_user/project_name/node_modules/my-service-one/node_modules/my-service-one/index.js'

WTF is this:
? Why?
It should use
. So why?

UPD: What I've already try(without result):

  • rm -rf node_modules

  • Restart;

  • Use node v4, v5, v6;

  • npm cache clean

  • Find other
    in wrong places inside project;

  • Google it;

This is bad question perhaps, but I'm really didn't know why it's happens. Thanks.

Answer Source

Have you tried to launch this modules with forever from command line?

This path issue looks like a bug for me, I think the obvious duct-tape type fix is use absolute path in services.json instead of relative. It will look terrible but it should work.

But I think it's better to install forever globally (with -g key) and then use a simple shell script to start your services with forever (two lines with something forever start /Users/my_user/project_name/node_modules/my-service-one/index.js) - this way works fine for me.

And also it's quite easy to start this script at the boot-up, or even write a script to start and stop your modules as a service.

UPD: This also may helps: sourceDir: './'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download