Pm2 error cannot find module

Good evening, I am using webfaction, and just found PM2 module. But I am getting probably a beginner issue. I have 2 apps running on webfaction. I run npm install pm2 -g while being on app2 folder....

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account


Closed

evalenzuela opened this issue

Feb 12, 2016

· 11 comments

Comments

@evalenzuela

Good evening,

I am using webfaction, and just found PM2 module. But I am getting probably a beginner issue.

I have 2 apps running on webfaction. I run npm install pm2 -g while being on app2 folder. If I run pm2 start —name=»app2″ —watch, all goes well. But then If I go to app1. and run pm2 start —name=»app1″ —watch. It appears an error: » cannot find module pm2/lib/ProcessContainerFork.js».

What I have noticed is that that file exists on app2 folder structure but no on app1. I guess I need to define a home dir or something?

Thanks in advance for your help

mqklin, AlexChesters, fritx, DavidHe1127, kstratis, giovannibenussi, akopchinskiy, runvnc, zhongdeming428, andre-brdoch, and AlexRMU reacted with thumbs up emoji

@Unitech

@maxinmos

I have the same issue. After some research, I followed a solution what I found on this stackoverflow.

Using rm -rf ~/.pm2 and it worked.

mqklin, Douvi, avocadowastaken, flayks, AlexChesters, oumayma-ltaief, ypadlyak, fritx, sarcastron, ajhsu, and 162 more reacted with thumbs up emoji
AlexRMU reacted with thumbs down emoji
gabrielmicko, unkleho, pietrograndi, edwinestrada, maodouchen, birmjin10000, avovk, samuelterra22, kstratis, dimpiax, and 30 more reacted with hooray emoji
unkleho, Angarsk8, jacobgarcia, ceharsh24, samuelterra22, kstratis, MohammedEssehemy, Tuhaj, GuihaiHU, VishalBheda, and 38 more reacted with heart emoji
duyleomessi, cobbweb, SamSverko, cyberz, adamalexander, AJLoveChina, loicsay, hampuskraft, lagoasoft-lucasschmidt, tnanhpt, and 16 more reacted with rocket emoji

@wojtek-krysiak

In my case pm2 update solved it

n3ps, Scoup, dtolstyi, zkday, rahuljain1311, maciejsikora, brandondoran, HorchataHTML, km42428, holyzfy, and 99 more reacted with thumbs up emoji
adityas3190, sysC0D, abhishekalai, moklick, alerad, lysla, kim366, dimpiax, giovannibenussi, rpf5573, and 22 more reacted with hooray emoji
abhishekalai, lysla, kim366, bharadhwaj, flameddd, spsenthilrm, giovannibenussi, rpf5573, jvcjunior, duyleomessi, and 27 more reacted with heart emoji
jvcjunior, duyleomessi, MWalid, cyberz, kimshinelove, otothea, tnanhpt, MarlonX19, asdjgfr, maxwellpas, and 3 more reacted with rocket emoji

@redhat-raptor

I just had to mkdir -p ~/.pm2/node_modules/

@Deniernal354

Hello I have the same error and I ran all the above commands but they where no use.
Here is my full error. I am doing this on a nodejs app.

1|app      | Error: Cannot find module '/root/.nvm/versions/node/v11.5.0/lib/node_modules/pm2/lib/ProcessContainerFork.js'
1|app      |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
1|app      |     at Function.Module._load (internal/modules/cjs/loader.js:529:25)
1|app      |     at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
1|app      |     at executeUserCode (internal/bootstrap/node.js:342:17)
1|app      |     at startExecution (internal/bootstrap/node.js:276:5)
1|app      |     at startup (internal/bootstrap/node.js:227:5)
1|app      |     at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

@khelkun

I have the same issue on Windows 10 with a pm2 global isntallation through npm. If I run pm2 start from the root folder of my nodejs expressjs application where lives the ecosystem.config.json:

0|ftl-node | Error: Cannot find module 'G:my-expressjs-node-appnode_modulespm2libProcessContainerFork.js'
0|ftl-node |     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:952:15)
0|ftl-node |     at Function.Module._load (internal/modules/cjs/loader.js:835:27)
0|ftl-node |     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
0|ftl-node |     at internal/main/run_main_module.js:17:47 {
0|ftl-node |   code: 'MODULE_NOT_FOUND',
0|ftl-node |   requireStack: []
0|ftl-node | }

If pm2 is installed as a local package of my nodejs application, then the issue does not occur…

@DaggieBlanqx

I have the same issue. After some research, I followed a solution what I found on this stackoverflow.

Using rm -rf ~/.pm2 and it worked.

It is 2021! and this answer worked for me! Thanks!

WaLinke reacted with thumbs up emoji
diegofigs, ronakvpanchal, Darker-Ink, farnetani, kosmotema, dongnl, roberto-red, Admsol, WilhelmStein, j1mmie, and WaLinke reacted with heart emoji

@tewedaj

pm2 start npm --name projectName -- run develop
this worked for me

@yangxiaolin

I have the same issue. After some research, I followed a solution what I found on this stackoverflow.

Using rm -rf ~/.pm2 and it worked.

it’s 2021-08. answer still work for me. cool

@tamurtaj85

I had 2 versions of node 16.x and 17.x and i installed pm2 globally two times by interchanging the node versions but it still didn’t work for me. Then i check the status of pm2 by deleting all the processes. And used the command «pm2 startup» to make it run at server startup. They will give a command just copy and paste the command and hit enter. After that run pm2 instance and you will be good to go.

@crazyoptimist

Thanks @maxinmos ❤️❤️
rm -rf .pm2 worked for me.

When you are working in Node, you will sometimes encounter the error Cannot find module 'module-name' with the error code MODULE_NOT_FOUND.

The error looks like this:

	internal/modules/cjs/loader.js:796
    throw err;
    ^

Error: Cannot find module 'module'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
    at internal/main/run_main_module.js:17:11 {
        code: 'MODULE_NOT_FOUND',
        requireStack: []
    }

In this post, we’ll learn how to resolve this error.

What is the problem?

The issue is that Node is unable to find the module that you are trying to import into your Node application.

The most common reason for this is that you simply haven’t installed the project’s dependencies yet.

The project’s dependencies are listed in the package.json file at the root of the project.

The Solution

To fix the Cannot find module error, simply install the missing modules using npm.

To so, you can use the following command:

	npm install

If you are using the yarn package manager, you can use the following command:

	yarn install

This will install the project’s dependencies into your project so that you can use them.

Sometimes, this might still not resolve it for you. In this case, you’ll want to just delete your node_modules folder and lock file (package-lock.json or yarn.lock) and try again.

This is how you can delete the node_modules folder and lock files:

	rm -rf node_modules

rm package-lock.json
rm yarn.lock

Local files

If your module is not coming from a remote source, you are seeing the error because the path to the local file is not correct.

Try to confirm that the path pointing to the local module is correct and your error should be resolved.

Conclusion

The Cannot find module error is a common error that usually happens when dependencies are not installed. Once you install your dependencies and ensure that the paths are correct, you can resolve the error and run your application successfully.

Hopefully, this resolved the issue for you.

Thanks for reading!

If you want to learn about web development, founding a start-up, bootstrapping a SaaS, and more, follow me on Twitter! You can also join the conversation over at our official Discord!

  • Support Us

  • Join

  • Share

  • Tweet

  • Share

Give feedback on this page!

Error: cannot find module [Node npm Error Solved]

If you’re a developer that works with Node JS and JavaScript libraries and frameworks like React, Vue, and Angular, then you might have encountered the «Error: cannot find module» error.

In this article, I’m going to show you how to fix the error.

Why the «Error: cannot find module» Occurs

This error occurs because of the following reasons:

  • you’re trying to import an item from a module you don’t have installed in your project directory
  • you’re importing some things from an outdated package
  • you’re pointing to a file that does not exist

In the screenshot below, you can see that I’m getting the error:

ss1

I’m getting the error because I’m trying to import the freeCodeCamp icon from the react-icons package, which I don’t have installed.

import { FaFreeCodeCamp } from "react-icons/fa";

How to Fix the «cannot find module» Error

If you get this error, the solution is always in the error. The module (package) not found is always specified in the format «Module not found: Error: Can’t resolve ‘package name’ in ‘project directory».

In my case, I got it like this «Module not found: Error: Can’t resolve ‘react-icons/fa’ in ‘C:UsersuserDesktopProjectsAddress Locatoraddress-locatorsrc'».

To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn add package-name.

In my case, I need to install the react-icons package so the freeCodeCamp icon can be resolved. I’ll do that by running yarn add react-icons.

Once I install the package and run the app, everything should successfully compile:

ss2

If you install the package but you still get the error, then follow the steps below:

  • delete the node modules folder by running rm -rf node_modules
  • delete package.lock.json file by running rm -f package-lock.json
  • clean up the NPM cache by running npm cache clean --force
  • install all packages again by running npm install

That should fix the error for you.

Conclusion

When you get the “cannot find module” error, or “module not found”, it means you’ve not installed the package you’re trying to use.

If the error occurs even if you have the package installed, then the fixes suggested in this article can help you out.

Thank you for reading.



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Понравилась статья? Поделить с друзьями:
  • Plumber found unhandled error
  • Plugin error typeerror не удалось получить свойство export ссылки значение которой не определено
  • Plugin error typeerror не удалось получить свойство close ссылки
  • Plugin error plugin android wifi adb is incompatible supported only in intellij idea
  • Please power down and connect the pcie power cable for this graphics card как исправить