nodejs Error

Error Cannot find module in Node.js - Causes and Solutions

When coding with the Node.js programming language, you may encounter the "Error: Cannot find module" error. This article covers how to handle and resolve this error.

Shou Arisaka
2 min read
Nov 13, 2025

When coding with the Node.js programming language, you may encounter the “Error: Cannot find module” error. This article covers how to handle and resolve this error.

Image

I think the number one cause of programming stumbling blocks happens during environment setup. Exactly like this. These causes are often due to installing directly on Windows or Mac rather than Linux, which causes fundamental issues - especially for beginners - but even with proper procedures, you sometimes encounter such problems and lose some time.

Whether you use global install or local install for npm install in Node.js determines whether this error occurs.

As I did, it’s somewhat difficult to grasp what local environment or local install really means. Setting that discussion aside for now, you can tell whether the current directory is a Node.js local directory with the following command.

ls "$( npm bin )"

Image

If you get an error saying the file doesn’t exist, it means it’s not a Node.js local directory, and if there’s some output, it suggests it is a local directory.

In a local directory, you can only use external packages installed with commands like npm install marked —save, but conversely, in directories that aren’t local directories, you can only use packages installed with commands like npm install -g marked.

Also, to turn the current directory into a local directory, you can either run the npm init command or execute commands like npm install [repo] —save to auto-generate it.

Summarizing all of this, we can say that the cause of the Error: Cannot find module error in the context we’re discussing is “the current directory is a local directory and cannot use globally installed external modules, yet a globally installed external package was required.”

Share this article

Shou Arisaka Nov 13, 2025

🔗 Copy Links