How to resolve can’t find module error in Node.js

How to resolve can’t find module error in Node.js

In this post we will give you information about How to resolve can’t find module error in Node.js. Hear we will give you detail about How to resolve can’t find module error in Node.jsAnd how to use it also give you demo for it if it is necessary.

we are going to learn about how to resolve can’t find a module error in Node.js.

If you are not installed a module properly using npm install command and trying to use it in your project by using require() function you will see this following error inside the terminal.

internal/modules/cjs/loader.js:796    throw err;    ^Error: Cannot find module '/Users/saigowtham/Desktop/sss/run'    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: []}

To fix Cannot find module errors, install the modules properly by running a npm install command in the appropriate directory as your project’s app.js or index.js file.

Here is an example:

# npm install your-module-namenpm install express

or delete the node_modules folder and package-lock.json file and re-install it again using the npm install command.

rm -rf node_modules package-lock.json

Can’t find modules in local files

If you are trying to import one local file inside another and passed a wrong path to the require() function you will see this error again.

To fix this error, pass a correct module path to the require() function.

Hope this code and post will helped you for implement How to resolve can’t find module error in Node.js. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US