Fixed Error: npm cannot find module error in NodeJS

featured Image

In this article we will see how to resolve npm cannot find module error in nodejs.

Cannot find module” usually occurs if we don’t properly install a package in our nodejs project using npm install.

And when we try to use the package in our project using require() function, it throws us an error in our terminal.

Sometimes it also occurs because of misspelling of the package name by developers too. So before proceeding towards the solutions make sure you have spelled the name of the package correctly 🙂.

So, there are two simple ways to solve the error:

Solution 1 : Re-install package using npm install

Sometimes the error occurs cause of corrupt installation.

To solve the “cannot find module” error we just have to install the packages properly by running npm install.

For scoped package, run:

npm install <@scope/package_name>

For unscoped package, run

npm install <package_name>

Solution 2 : Delete module_modules and package-lock.json

If the solution 1 didn’t work for you then try this.

Just delete the node_modules folder and package-lock.json file and then run:

npm install

It will reinstall all the packages needed for you application again.

NOTE: Do not delete the package.json file, just delete the package-lock.json file


Related Topics:

How To Fix “Npm ERR Cb() Never Called” | Quick Fix

Resolve Npm Cannot Find Module Error In Nodejs

Solve npm ERR! ENOENT – No Such File or Directory Error

Fixed Error: npm cannot find module error in NodeJS

npm WARN : No description field in Node – Fix

Fixed Error – npm ERR! missing script: dev

NVM Error – exit status 1: Access is denied – Fixed

(Fixed) npm ERR! missing script: start error

Fix error:0308010C:digital envelope routines::unsupported

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more