node.js npm 不起作用,总是出现这个错误 -> 错误:找不到模块“我们在那里”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31025048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
npm doesn't work, get always this error -> Error: Cannot find module 'are-we-there-yet'
提问by Gregor Voinov
i tried to install grunt on a mac with Yosemite. node is already installed in the newest version. if i type "node -v" in the terminal i get the line v0.12.5. thats good. but when i want to install something with npm i get only a error...
我尝试在带有 Yosemite 的 Mac 上安装 grunt。node 已经安装在最新版本中。如果我在终端中输入“node -v”,我会得到 v0.12.5 行。那挺好的。但是当我想用 npm 安装一些东西时,我只会得到一个错误......
i tried "sudo npm install -g grunt-cli", "sudo npm install npm -g" and also with "npm -v" i get always this error...
我试过“sudo npm install -g grunt-cli”、“sudo npm install npm -g”以及“npm -v”我总是得到这个错误......
Error: Cannot find module 'are-we-there-yet'
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 Object.<anonymous> (/usr/local/Cellar/node/0.10.22/lib/node_modules/npm/node_modules/npmlog/log.js:2:16)
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)
at Module.require (module.js:365:17)
someone knows what's the problem or better a solution?
有人知道是什么问题或更好的解决方案吗?
回答by eush77
You have broken npmby removing some of its dependencies.
你已经npm通过删除它的一些依赖项而破坏了。
are-we-there-yetis a dependency of npmlogwhich is a dependency of npmitself, and you somehow deleted it. The usual simple solution for such cases is reinstalling a package, but that doesn't work if npmcannot operate. Fortunately, npmtarball comes prebundled with dependencies and hence installing npmfrom scratchis as simple as unpacking a tarball.
are-we-there-yet是一个依赖,npmlog它npm本身就是一个依赖,你以某种方式删除了它。对于这种情况,通常的简单解决方案是重新安装软件包,但如果npm无法运行,则不起作用。幸运的是,npmtarball 预先捆绑了依赖项,因此从头开始安装npm就像解压 tarball 一样简单。
1) Go to the global node_modulesdirectory (what would npm root -gprint if you could run it):
1)转到全局node_modules目录(npm root -g如果可以运行它会打印什么):
$ cd /usr/local/lib/node_modules
2) Remove the broken npmdirectory or move it somewhere else (note that you might need to elevate permissions for this and the following steps):
2) 删除损坏的npm目录或将其移至其他位置(请注意,您可能需要为此和以下步骤提升权限):
$ mv npm /tmp
3) Download and unpack fresh npmfrom the registry (substitute version you want to install, e.g. 3.10.8):
3)npm从注册表下载并解压新鲜(您要安装的替代版本,例如3.10.8):
$ curl -L registry.npmjs.com/npm/-/npm-{VERSION}.tgz | tar xz --transform="s:^package:npm:"
You can automate some of that with this install script:
您可以使用此安装脚本自动执行其中的一些操作:
$ curl -L https://www.npmjs.com/install.sh | sh
At this point npmshould work again.
此时npm应该再次工作。
回答by Sam Quayle
Go to the global node_modules directory (npm root -g if you don't know)
转到全局 node_modules 目录(npm root -g 如果不知道)
$ cd /usr/local/lib/node_modules
curl -L https://www.npmjs.com/install.sh | sh
回答by The Lazy Coder
I have been trying feverishly to get to the latest version of node and npm on my centos 7 machine.
我一直在狂热地尝试在我的 centos 7 机器上获得最新版本的 node 和 npm。
Unfortunately, I have been plagued with this error for near a week now. And I have finally found a solution that works.
不幸的是,我被这个错误困扰了将近一个星期。我终于找到了一个有效的解决方案。
If your npm is currently broken, It is easiest just to install a working version again.
如果您的 npm 当前已损坏,最简单的方法是再次安装工作版本。
I installed from code. Assuming git is installed, the following commands will accomplish that goal
我从代码安装。假设安装了 git,以下命令将实现该目标
cd ~
git clone https://github.com/nodejs/node.git nodejs_code
cd nodejs_code
./configure
make
make install
After you have installed a fresh copy of npm and node, which by the way is not the stable version (Instead its bleeding edge right from source).
在您安装了 npm 和 node 的新副本之后,顺便说一下,这不是稳定版本(而是从源代码中提取的前沿)。
Installed version of node at time of writing this was 5.0.0-pre which is too new for me, and npm was version 2.14.4 which is too old for me.
在撰写本文时安装的 node 版本是 5.0.0-pre,这对我来说太新了,而 npm 是 2.14.4 版,这对我来说太旧了。
To get to the latest version on node, I will install the 'n' package using npm. Using n, I will install the latest version of node.
为了获得 node 上的最新版本,我将使用 npm 安装“n”包。使用 n,我将安装最新版本的 node。
npm install -g n
n stable
In the case of the root user, (which I use to install global packages) I needed to add the following line to my ~/.bashrcfile, which will allow the root user to access the commands in /usr/local/bin commands. (You may not need this step)
在 root 用户的情况下,(我用来安装全局包)我需要~/.bashrc将以下行添加到我的文件中,这将允许 root 用户访问 /usr/local/bin 命令中的命令。(您可能不需要此步骤)
export PATH=/usr/local/bin:$PATH
At this point my version of node is 4.0.0 which is the latest stable version of node.
此时我的 node 版本是 4.0.0,这是 node 的最新稳定版本。
now to update npm, which was the most annoying thing ever.
现在更新 npm,这是有史以来最烦人的事情。
Updating directly to the newest version always resulted in "are-we-there-yet" which I could only surmise as "NO, and Quit Asking or I will turn this node around"
直接更新到最新版本总是导致“我们在那里”,我只能推测为“不,退出询问,否则我将扭转这个节点”
Instead I have found that installing through version 3.3.3 first would solve this problem.
相反,我发现首先通过 3.3.3 版安装可以解决这个问题。
npm install -g [email protected]
now version 3.3.3 is installed and works without the "are-we-there-yet" error.
现在版本 3.3.3 已安装并且可以正常工作,而不会出现“are-we-there-yet”错误。
Thank goodness. Keep your arms inside and you seatbelts fastened kids, because we are almost there.....
谢天谢地。把你的手臂放在里面,你系好安全带的孩子们,因为我们快到了......
npm install -g npm
and with that final command, I was able to use the latest version of npm, with the latest stable version of node. Which at the time of writing this is 3.3.5
使用最后的命令,我能够使用最新版本的 npm,以及最新的稳定版本的 node。在撰写本文时,这是 3.3.5
From here on out, my commands are as follows.
从这里开始,我的命令如下。
n stable
npm install -g npm
each time I run these from here on out, I am granted undisturbed npm trips without the kids complaining in the back.
从现在开始,每次我运行这些时,我都可以不受干扰地进行 npm 旅行,而孩子们不会在后面抱怨。
Note
笔记
As I am moderating a number of servers, none of which come with node by default, I find myself having to perform this task over and over..
由于我正在管理许多服务器,默认情况下这些服务器都没有节点,我发现自己必须一遍又一遍地执行此任务..
Therefore I have taken it upon myself to turn these instructions into a script.
因此,我自己将这些说明变成了脚本。
Enjoy:
享受:
importnode.sh
导入节点.sh
#!/bin/bash
cd ~
git clone https://github.com/nodejs/node.git nodejs_code
cd nodejs_code
git reset --hard
git pull origin master
./configure
make
make install
if [[ `cat ~/.bashrc |grep -E "PATH.*/usr/local/bin:.*"` ]];
then
echo "Already Done";
else
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bashrc;
export PATH=/usr/local/bin:$PATH;
fi;
npm install -g n
n stable
npm install -g [email protected]
npm install -g npm
The only thing left to do after putting this into nodeimport.sh is to make it executable and execute it.
将其放入 nodeimport.sh 后唯一要做的就是使其可执行并执行它。
$ chmod +x importnode.sh
$ ./importnode.sh
Wait a while, and all is installed.
稍等片刻,一切就安装好了。
回答by user2656961
What eush77 said, but if you're on Windows:
eush77 所说的,但如果您使用的是 Windows:
download the latest package from https://nodejs.org/download/release/npm/
从https://nodejs.org/download/release/npm/下载最新的包
unpack, and replace the "npm" directory in the nodejs node-modules directory (by default C:\Program Files\nodejs\node_modules)
解压,替换nodejs node-modules目录下的“npm”目录(默认为C:\Program Files\nodejs\node_modules)
回答by santhosh
Even i had same issue, Easiest way to solve below steps worked for me.
即使我有同样的问题,解决以下步骤的最简单方法对我有用。
1) uninstall Nodejs.
1)卸载Nodejs。
2) Go to C:/User/AppData/Roaming.
2) 前往 C:/User/AppData/Roaming.
3) Delete npmdirectory.
3) 删除npm目录。
4) Reinstall Nodejs(latest v6.11.3,includes npm 3.10.10).
4)重新安装Nodejs(最新的v6.11.3,包括npm 3.10.10)。
5) Done Now try to check (npm -v) will be working fine.
5) 完成 现在尝试检查 ( npm -v) 是否能正常工作。
回答by ocolot
You could also reinstall nodefrom https://nodejs.org/en/download/current/
您也可以node从https://nodejs.org/en/download/current/
回答by Walker Rowe
I followed the instructions above (what eush77 said) to remove the npm folder in the node_modules folder. But there remains the broken link resulting in this error message.
我按照上面的说明(eush77 说的)删除了 node_modules 文件夹中的 npm 文件夹。但是仍然存在导致此错误消息的断开链接。
/usr/local/bin/npm: No such file or directory
/usr/local/bin/npm: 没有那个文件或目录
so remove the broken link:
所以删除断开的链接:
rm /usr/local/bin/npm
rm /usr/local/bin/npm
and then make it point to the right place like this:
然后让它指向正确的位置,如下所示:
sudo ln -s /usr/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
sudo ln -s /usr/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
回答by Yann VR
I got it reset by using the official installer package found: https://nodejs.org/en/
我使用找到的官方安装程序包重置了它:https: //nodejs.org/en/
Playing around with n and nvm eventually corrupted the node_modules packages for me by providing packages incompatible with current Node version.
通过提供与当前 Node 版本不兼容的包,使用 n 和 nvm 最终破坏了我的 node_modules 包。
I suspect it'd work for other environments as it couples both Node AND npm install.
我怀疑它适用于其他环境,因为它结合了 Node 和 npm install。
回答by edencorbin
For me this had to do with installations being corrupted and perhaps ubuntu repositories not being compatible or the most recent. The following resulted in a working npm/node install:
对我来说,这与安装被破坏有关,也许 ubuntu 存储库不兼容或最新的。以下导致运行 npm/node 安装:
sudo curl -sL https://deb.nodesource.com/setup_4.x| sudo -E bash - sudo apt-get install -y nodejs
须藤卷曲-sL https://deb.nodesource.com/setup_4.x| 须藤 -E bash - 须藤 apt-get install -y nodejs
回答by Mikeumus
For me, I had to remove my project's node_modulesfolder. I then cleaned the cache just in case and did a fresh npm iand it was able to do the node-sass post-install and not error at are-we-there-yetmissing.
对我来说,我必须删除我的项目node_modules文件夹。然后我清理了缓存以防万一并重新做了一次npm i,它能够在安装后执行 node-sass 并且不会在are-we-there-yet丢失时出错。
If moving global node_modulesdoesn't work for you like in the solutions above try:
如果node_modules在上面的解决方案中移动全局对您不起作用,请尝试:
- Remove your project's local
node_modules- In your project's root:
rm -rf node_moduldes
- In your project's root:
npm cache clean -fnpm i
- 删除项目的本地
node_modules- 在您的项目根目录中:
rm -rf node_moduldes
- 在您的项目根目录中:
npm cache clean -fnpm i

