[Solved] Understanding and Resolving the “node:internal/modules/cjs/loader” Error in Windows 10 – Javascript

Photo of author
Written By M Ibrahim
javascript node.js nodemodules npm npminstall

The Problem:

You may encounter the following error in Windows 10 when running npm commands:
"node:internal/modules/cjs/loader:1078 throw err; ^.
Error: Cannot find module ‘D:\mobile-version portfolio
at Module._resolveFilename (node:internal/modules/cjs/loader:1060:15)
at node:internal/main/check_syntax:34:20 {
code: ‘MODULE_NOT_FOUND’,
requireStack: []
}"

This error typically occurs when Node.js cannot find the specified module or file. It can be frustrating, especially when trying to run npm commands and update files. In this article, we will explore various solutions to help you resolve this error and continue working with your Node.js projects in Windows 10.

Solution: Opening the Terminal in the Correct Folder

One common reason for this error is opening the terminal in the wrong folder. Ensure that you are in the correct directory that contains the index file. For example, if your index file is inside the "BestMe" folder located at "~/Desktop/Programação/Rocketseat/Discover/NodeJS/BestMe", make sure your terminal is opened within that folder. This simple step can resolve the error.

Opening Terminal in the Correct Folder

Installing stylelint Globally
Another possible solution is to install "stylelint" globally using the following command:

npm i -g stylelint@version

This solution has worked for some users facing the same error. Installing "stylelint" globally may help resolve the module not found issue.

Conclusion:

The "node:internal/modules/cjs/loader" error can occur when Node.js cannot find the specified module or file. To resolve this error in Windows 10, make sure to open the terminal in the correct folder that contains the index file. Additionally, installing "stylelint" globally may help resolve the module not found issue. By following these solutions, you should be able to resolve the error and continue working with your Node.js projects smoothly.

Note: It’s always a good practice to refer to official documentation or reliable sources for more detailed information on the specific error or issue you are facing.