node.js 已安装 karma 时找不到 karma 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17704106/
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
karma command not found when karma already installed
提问by iChido
I used node.js to install karma. My first try failed when running the following command on Terminal:
我使用 node.js 来安装 karma。在终端上运行以下命令时,我的第一次尝试失败:
npm install -g karma
That failed so I decided to use:
那失败了,所以我决定使用:
sudo npm install -g karma
After entering my password it seemed to install correctly. I am pasting part of the output of the install, maybe it will mean something to someone and it will be relevant to my question. After all the npm http messages this is what I see:
输入密码后,它似乎安装正确。我正在粘贴安装输出的一部分,也许它对某人有意义,并且与我的问题相关。在所有 npm http 消息之后,这就是我所看到的:
> [email protected] install /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/bufferutil.node
SOLINK_MODULE(target) Release/bufferutil.node: Finished
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/validation.node
SOLINK_MODULE(target) Release/validation.node: Finished
/usr/local/share/npm/bin/karma -> /usr/local/share/npm/lib/node_modules/karma/bin/karma
[email protected] /usr/local/share/npm/lib/node_modules/karma
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected])
Then when I try to run the following command to create a karma config file with this command:
然后,当我尝试运行以下命令以使用此命令创建 karma 配置文件时:
karma init karma.config.js
this is the message that gets returned:
这是返回的消息:
-bash: karma: command not found
I have tried the same command with sudo before it but I get the same result.
我之前用 sudo 尝试过相同的命令,但我得到了相同的结果。
Does anyone have any idea as to what is going on? Any help is appreciated.
有没有人知道发生了什么?任何帮助表示赞赏。
*Update! I decided to check a file named: builderror.log located in: /usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
*更新!我决定检查一个名为:builderror.log 的文件位于:/usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
This is what it shows:
这是它显示的内容:
gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/eperez/.node-gyp/0.10.5"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/share/npm/lib/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws/.node-gyp"
gyp http GET http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
gyp http 200 http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz
回答by Kirkland
@mayankcpdixitgave the answer up there in a response to the OP's original question, but I'll put it here again in case anyone misses it.
@mayankcpdixit在回答 OP 的原始问题时给出了答案,但我会再次将其放在这里,以防有人错过。
You do not need to uninstall everything, and if I had to manually add a new path link for every npm package I try to install I'd probably shoot myself.
你不需要卸载所有东西,如果我必须为我尝试安装的每个 npm 包手动添加一个新的路径链接,我可能会自杀。
npm install -g karma-cli
Boom. Now you have karma command lines installed. Just like Grunt.
繁荣。现在您已经安装了 karma 命令行。就像咕噜一样。
Edit: Please don't forget to upvote @mayankcpdixitas well, he commented directly on the original post, but didn't actually "answer" the question.
编辑:也请不要忘记给@mayankcpdixit 点赞,他直接对原帖发表了评论,但实际上并没有“回答”这个问题。
回答by Marty Cortez
In your ~/.bash_profile(or similar) amend your PATHto include npm-installed binaries:
在您的~/.bash_profile(或类似的)修改您的PATH以包含 npm 安装的二进制文件:
export PATH="$PATH:/usr/local/share/npm/bin"
I had this very same issue, and found this solution to be less time-consuming and impactful than completely re-installing node.
我遇到了同样的问题,并发现此解决方案比完全重新安装 node.js 更耗时且影响更小。
EDITthis has also worked for others in bash_profile
编辑这也适用于其他人bash_profile
export PATH="$PATH:/usr/local/lib/node_modules/karma/bin"
回答by Lior Elrom
It is recommended to install karma with its Command-Line-Interface (karma-cli) which will take care of fetching the appropriate karma. You can also install a different local version specific to each project you're working on and karma-cli will pick the appropriate one.
建议使用其命令行界面 ( karma-cli)安装 karma ,它将负责获取适当的 karma。您还可以安装特定于您正在处理的每个项目的不同本地版本,karma-cli 将选择合适的版本。
From the karma installationpage:
从业力安装页面:
Typing ./node_modules/karma/bin/karma startsucks so you might find it useful to install karma-cli globally:
输入./node_modules/karma/bin/karma start 很糟糕,所以你可能会发现全局安装 karma-cli 很有用:
npm install -g karma-cli
Now, check that karma was installed by typing:
现在,通过键入以下内容检查是否已安装 karma:
karma start
You can also check that karma was installed by going to this directory:
您还可以通过转到此目录来检查是否已安装 karma:
cd /usr/local/lib/node_modules/karma
Good luck!
祝你好运!
回答by vusan
Don't need to completely uninstall node.js
不需要完全卸载node.js
Just
只是
sudo rm -rf /usr/local/lib/node_modules/npm/
Then
install node.js
然后
安装 node.js
Then
reinstall karma
然后
重新安装业力
This worked for me.
这对我有用。
回答by Ralph Delzepich
I had to add export PATH="$PATH":/usr/local/lib/node_modules/npm/node_modules/karma/binafter installing karma with sudo npm install karma.
我必须export PATH="$PATH":/usr/local/lib/node_modules/npm/node_modules/karma/bin在使用sudo npm install karma.
hope this helps.
希望这可以帮助。
回答by Tiago Ferreira
Just go to test.sh:
只需转到 test.sh:
Find: $BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/karma.conf.js $*
找: $BASE_DIR/../node_modules/karma/bin/karma start $BASE_DIR/../config/karma.conf.js $*
Replace with: /usr/local/bin/karma start $BASE_DIR/../config/karma.conf.js $*
用。。。来代替: /usr/local/bin/karma start $BASE_DIR/../config/karma.conf.js $*
Or: karma start $BASE_DIR/../config/karma.conf.js $*
或者: karma start $BASE_DIR/../config/karma.conf.js $*
回答by skjoshi
I was also facing the same issue. It looks like karma for command line is a separate package which can be installed by
我也面临同样的问题。看起来命令行的 karma 是一个单独的包,可以通过以下方式安装
npm install -g karma-cli
npm install -g karma-cli
回答by OnnoH
When upgrading from Karma 0.10 to 0.12 the link to the karma executable is removed.
从 Karma 0.10 升级到 0.12 时,指向 karma 可执行文件的链接将被删除。
You can get it back with
你可以把它拿回来
cd node_modules/.bin
ln -s ../karma/bin/karma karma
回答by dob
Try re-installing node.js. There are lots of ways to install it, but I recommend downloading from nodejs.org
尝试重新安装 node.js。有很多安装方法,但我建议从nodejs.org下载
If that doesn't work, you may try to re-install karma.
如果这不起作用,您可以尝试重新安装 karma。

