Installing MEAN Stack: npm -v module.js: 338 throw err; Error: Cannot find module './cache/caching-client.js'

删除回忆录丶 提交于 2019-12-11 03:09:44

问题


I think I have installed node.js before but never used homebrew to do it. Today I tried to do a walkthrough of an application but got stuck at the very beginning. I am fairly new to programming so I am utterly confused as to why I can't get this to work.

I have tried a lot of things but can't seem to find the answer.

These are the commands I run in order to install the MEAN stack:

  1. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" (succesful no errors)
  2. brew install node (succesfull no errors)
  3. I check if node has installed properly by typing: node -v v0.12.4
  4. I then check if npm is installed properly by typing: npm -v

Here is the error message:

module.js:338
    throw err;
          ^
Error: Cannot find module './cache/caching-client.js'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at /usr/local/lib/node_modules/npm/lib/npm.js:22:24
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:466:3)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

I have installed node in a different way other than using Homebrew and maybe that is messing things up. Please let me know your thoughts.

What I have tried to do so far is uninstall node and reinstall it using this process: https://gist.github.com/DanHerbert/9520689


回答1:


Maybe you've already fixed, but the answer might serve others.

I tried what is in the post that Mario linked to in his comment, but it didn't work. It just so happens that my npm is installed at /Users/USERNAME/.node/bin/, so I added the following line in my .bash_profile file: export PATH="$HOME/.node/bin:$PATH".




回答2:


In my case it was caused by me installing node with root and later with brew (without root).

As a result brew was not able to override the old npm files upon upgrading.

Manually removing the old node installation worked for me.



来源:https://stackoverflow.com/questions/30948437/installing-mean-stack-npm-v-module-js-338-throw-err-error-cannot-find-modul

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!