In this post, we will see How To Fix - "Error: Cannot Find Module" in Node.js. Sample error
module.js:123
throw err;
Error: Cannot find module 'XXXX'
code: 'MODULE\_NOT\_FOUND',
$ cd <project\_directory\_path>
$ npm list
If you want to list the globally installed packages, use below command in the project directory -
$ cd <project\_directory\_path>
$ npm -g list
If you don't want the listing of dependencies, use below command -
$ npm list -g –depth= 0
To check whether a specific package is installed or not, use below command -
$ npm list -g \[package-name\]
$ npm install <package\_name>
For scoped package i.e. scope name is referenced during installation
$ npm install @scope/package-name
npm install @scope/private-package-name
$ yarn init
$ yarn install
$ yarn add package-name
rm -rf node\_modules
rm package-lock.json
rm yarn.lock
Hope this helps to solve the error.
node cannot find module local file,error: cannot find module local file,error: cannot find module 'node:url',error: cannot find module 'typescript,cannot find module require stack,error: cannot find module 'react,error \[err\_module\_not\_found\]: cannot find module,cannot find module even though it is there,node.js error handling,node.js error cannot find module,node.js error object,node.js error handling best practices,node.js error log file,node.js error 2503,node.js error getaddrinfo enotfound,node.js error handling try catch,node.js error code 2503,node.js not working