PM2 cluster mode Cannot find module - node.js

I used pm2 for run my nodejs application for production in cluster mode.
The problem is after I check the error logs I find these weird logs:
Cannot find module 'winston'
Cannot find module '#turf/destination'
Cannot find module 'apollo-server-redis'
Cannot find module ...
They are just random package names and I have installed theme and they work fine but only SOMETIMES they act weird and cause problem in my web application.
Is this problem related to PM2 or my packages or my code?
What should I do?

try sudo pm2 update - could be that your node_modules folder isn't in the correct folder aswell...

Related

Node cannot run serverless cmd

I tried updating both Serverless module and Node, but still receives the same error.
I count not even find the solution in the internet for this simple problem.
can someone suggest.
The issue for me was that I was missing the following directory in my Windows PATH env variable:
%AppData%\npm
Once I added that I could run serverless, SLS, etc.
Don't forget the restart your PC.

how to fix "Error: Cannot find module '/home/container/index.js'", I've tried everything

So the host that I use for my discord bot died so I downloaded all the code and tried hosting it on my PC. But I get the following error.
Error: Cannot find module '/home/container/index.js
I've tried everything I can:
updated nodejs
reinstalled all my packages
Changed package.json
How can I fix this?
Cannot find module means you are trying to run non-existent file.
Ensure there is index.js in your working directory. If not,
Use cd to go to the directory where it is (usually it's src near the package.json)
Run node ./index.js
Many time people have just the problem of command line to run file,
as windows and linux have
different syntax to run .js file
i.e. node ./index.js for linux
and node .\index.js for windows

PM2 starting Meteor App not working

I have in one Digital Ocean Linux Ubuntu 16.041 droplet an instance of a Meteor app. Moreover, I installed Node.js version of 4.4.0
I created the respective bundle on the path ~/MyApplication/bundle. As a matter of fact, I automated with a config.json file the execution which its body contains the following code:
My main.js file is created from the Meteor build --directory ~/myDirectory/ command and contains the following code:
process.argv.splice(2, 0, 'program.json');
process.chdir(require('path').join(__dirname, 'programs', 'server'));
require('./programs/server/boot.js');
That being said, I run my application with pm2 through the config JSON file with pm2 start config.json
It starts the application, but several ms afterwards it is errored. The log error show the following exception regarding the typo, but seems the mainjs file is created fine. Any suggestions to solve it?
In the end, I had to update the node version in the server from 4.4.0 to 8.9.1. After doing that changes, I also had to install the dependencies within the bundle/programs/server/ using npm install

Node can't start app due to missing module

I have an application that I am running for the first time in a new computer. I keep getting the following error when starting the app
Error: Cannot find module './src/async'
I checked the application directory and I see the module there. I have tried re-installing the module and doing npm install and still no luck.

node jitsu cannot find local modules

I have an application successfully working locally so I know the code works. However when I go to deploy to node jitsu I get an error that it cannot find a local module. Here is what I have:
File Setup:
/index.js
/config/config.js
index.js
var cfg = require('./config/config.js');
When trying to deploy node jitsu is giving me an error:
Error: Cannot find module './config/config.js'
Since all this code works locally I do not believe this is a coding issue. I am under the impression that local modules do not need to be included in package.json but perhaps they do for node jitsu? I read their documentation but cannot find anything special for local modules.
Thanks!
Local modules like this should work properly.. so long as you don't have it in .gitignore or .npmignore.
Modules in the node_modules directory require that you add it to the bundledDependencies array in your package.json file.
An easy way to check for whether the file is included in your deploy is to run tar -tf $(npm pack).
I had this exact same error on deploy, but caused by a different root cause. In case anybody stumbles into the same problem:
File Setup:
/public/Data/TargetData.js
app.js require statement:
var target = require('./public/data/TargetData.js');
My local Mac OSX environment allowed the capitalization difference of /data/ vs. /Data/ - the Nodejitsu server did not.

Resources