After removing the older version of nvm, i installed the latest version of node by using homebrew. However, i got some problem starting my project using pm2:
pm2-dev server.js
It loaded the path including nvm. Here is the log:
Error: Cannot find module '/Users/wyb/.nvm/versions/io.js/v3.0.0/lib/node_modules/pm2/lib/ProcessContainerFork.js'
The cannot find module error occurs because NPM cannot find the module required by the index.js file. In this case, the axios module. To resolve the error, you need to make sure that axios is installed in the node_modules/ folder.
To conclude, the error “Cannot find module” happens when Node.js can’t find the module that a file is trying to import. You can see the file and the module that’s causing the issue from the error output generated by Node itself.
If you are trying to run your Node.js application and you get something like this: Error: Cannot find module 'C:UsersMemy_app.js'. then you are most likely trying to run the wrong file.
For TypeScript users, if you are importing a built-in Node module (such as http, pathor url) and you are getting an error such as "Cannot find module "x"then the error can be fixed by running npm install @types/node --save-dev
The reason is you pm2 env is modified, please try run command below to delete your pm2 env dir from your home dir.
rm -rf ~/.pm2
Now rerun your pm2-dev server.js
, pm2 will refresh env.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With