Home > Back-end >  --FIXED-- 'MODULE_NOT_FOUND' npm commands error
--FIXED-- 'MODULE_NOT_FOUND' npm commands error

Time:08-28

I'm learning JavaScript with "Morten Rand-Hendriksen" on LinkedIn Learning. And the instructor said we need to install "Prettier" on our VSCode. He said that after installing it from the "Extensions" in VSCode, we will open the exercise folder on VSCode and type in the terminal npm install but when I do so this message appears.

PS C:\Users\ytrip\OneDrive\Desktop\javascript-essential-training-2832077-main> npm install
node:internal/modules/cjs/loader:364
      const err = new Error(
                  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\are-we-there-yet\node_modules\readable-stream\readable.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:364:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:577:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\are-we-there-yet\lib\tracker-stream.js:3:14)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\are-we-there-yet\\node_modules\\readable-stream\\package.json',   
  requestPath: 'readable-stream'
}
node:internal/modules/cjs/loader:364
      const err = new Error(
                  ^

Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\node_modules\are-we-there-yet\node_modules\readable-stream\readable.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (node:internal/modules/cjs/loader:364:19)
    at Function.Module._findPath (node:internal/modules/cjs/loader:577:18)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:942:27)
    at Function.Module._load (node:internal/modules/cjs/loader:804:27)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\are-we-there-yet\lib\tracker-stream.js:3:14)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\are-we-there-yet\\node_modules\\readable-stream\\package.json',   
  requestPath: 'readable-stream'
}

I'm new in this field and I really couldn't find a solution for this problem. So I'd appreciate your help. And unfortunately, no help is being provided in the discussion forum on LinkedIn Learning.

package.json:

{
  "name": "javascript-essential-training-exercise-files",
  "version": "1.0.0",
  "description": "Repository for exercise files used in the LinkedIn Learning course `JavaScript Essential Training` instructed by Morten Rand-Hendriksen and published 2020.",
  "main": "index.html",
  "author": "Morten Rand-Hendriksen",
  "license": "SEE LICENSE IN LICENSE",
  "devDependencies": {
    "eslint": "^7.11.0",
    "eslint-config-standard": "^14.1.1",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.2.1",
    "eslint-plugin-standard": "^4.0.1",
    "prettier": "^2.1.2"
  }
}

The repository for this exercise folder is here if anyone want to have a look.

CodePudding user response:

You can check in this reference. I think your problem same with this, you can read and try this solution : Error: Cannot find module 'C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\npm-cli.js' when trying to run npm

Hope you can solve your problem.

CodePudding user response:

So, despite all the suggested solves I received from StackOverFLow and npm GitHub Support and all the search I've done, none of it worked for me, so I started trying to solve it myself, and fortunately, I HAVE FOUND A FIX FOR THIS ISSUE.

THE PROBLEM

So the problem appears because npm terminal is trying to find the files in directory C:\Program Files\nodejs\node_modules\npm\bin\node_modules\npm\bin\ If you notice, the sub directory node_modules\npm\bin is repeated twice even though the actual correct directory is C:\Program Files\nodejs\node_modules\npm\bin, and that's what was causing the error MODULE_NOT_FOUND because it obviously can not find the modules there.

THE FIX

So in order to solve this issue, I made a new folder inside the bin folder and copied the node_modules folder that npm was looking for into that directory. And that eventually solved the problem! I don't know why npm is trying to search for the modules in that directory but, I hope it gets fixed by npm as I shared that conclusion with them.

Hope this helps anyone who's trying to learn like me but faces this problem.

You can find the article I wrote about this problem and fix on my LinkedIn profile here.

CodePudding user response:

Did you try to remove your node_modules folder In some case it works

  • Related