Posted on Leave a comment

How to fix the Node error “Cannot find module”

Sometimes you can get this error when installing a new module in your application.

module.js:471
throw err;
^

Error: Cannot find module ‘@sendgrid/mail’
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/var/www/html/msg.js:2:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

In most cases the fix is to just check if you installed the module in the right folder of the application you need.
So, being in your current application folder, type again npm install your_module.

If that does not work, you have to delete the node_modules folder in your local app folder then type

npm install

or if that does not work either you have to delete package.json and package_locked.json files then npm install again.