node.js 安装后运行 karma 导致“karma”不被识别为内部或外部命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20800933/
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
Running karma after installation results in 'karma' is not recognized as an internal or external command
提问by Liad Livnat
I'm trying to run karma as part as an angular-seedproject, after installing karma using
在使用安装 karma 之后,我试图将 karma 作为angular-seed项目的一部分运行
npm install -g karma
I get:
我得到:
'karma' is not recognized as an internal or external command, operable program or batch file.
when i'm trying to run test.bat from angular-client\scripts, the content of this file is:
当我试图从 angular-client\scripts 运行 test.bat 时,这个文件的内容是:
set BASE_DIR=%~dp0
karma start "%BASE_DIR%..\config\karma.conf.js" %*
设置 BASE_DIR=%~dp0
业力开始“%BASE_DIR%..\config\karma.conf.js”%*
I also tried to navigate to "\AppData\Roaming\npm\node_modules\karma\bin" and saw karma file, when I'm trying to run it I get again:
我还尝试导航到“\AppData\Roaming\npm\node_modules\karma\bin”并看到 karma 文件,当我尝试运行它时,我再次得到:
'karma' is not recognized as an internal or external command, operable program or batch file.
'karma' 不是内部或外部命令,也不是可运行的程序或批处理文件。
Any suggestions? If not please suggest how to use jasmine without karma.
有什么建议?如果没有,请建议如何在没有业力的情况下使用茉莉花。
Thanks.
谢谢。
回答by MrCheese
The command line interface is in a separate package.
命令行界面在一个单独的包中。
To install this use:
要安装此使用:
npm install -g karma-cli
npm install -g karma-cli
回答by Lior Elrom
karma-cli
因果报应
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:
which karma //echo something like: /usr/local/bin/karma
and check that karma server is working (ctr+c to quit):
并检查 karma 服务器是否正常工作(ctr+c 退出):
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 Alexander Williamson
On windows when you install a npm (non-globally - so without the -gflag), the executable commands are linked in the node_modules\.binfolder.
在 Windows 上,当您安装 npm(非全局 - 所以没有-g标志)时,可执行命令链接在node_modules\.bin文件夹中。
For example:
例如:
powershell> .\node_modules\.bin\karma start
powershell> .\node_modules\.bin\karma start
powershell> .\node_modules\.bin\karma run
powershell> .\node_modules\.bin\karma run
回答by ajaysinghdav10d
I had the same issue and fixed it by correcting my PATH environment variable.
我遇到了同样的问题并通过更正我的 PATH 环境变量来修复它。
STEP 1:go to the following path and ensure karma.cmd is present at the location given below
步骤 1:转到以下路径并确保 karma.cmd 存在于下面给出的位置
[Nodejs folder path]\node_modules\.bin<=> C:\Program Files\nodejs\node_modules\.bin
[Nodejs 文件夹路径]\node_modules\.bin<=> C:\Program Files\nodejs\node_modules\.bin
STEP 2:If present go to STEP 3, If not present run the following command npm install -g karma
第 2 步:如果存在,请转到第 3步,如果不存在,请运行以下命令npm install -g karma
STEP 3:Open environment variables and edit PATH
第 3 步:打开环境变量并编辑 PATH
STEP 4:Add the following at the end :
第 4 步:在最后添加以下内容:
[Nodejs folder path]\node_modules\.bin;<=> "C:\Program Files\nodejs\node_modules\.bin"
[Nodejs文件夹路径]\node_modules\.bin; <=> "C:\Program Files\nodejs\node_modules\.bin"
Log out your session and it will work for sure.
注销您的会话,它肯定会起作用。
回答by Matthew Bakaitis
Based upon your directory using \AppData\Roaming, you're on Windows and this error is usually because the path to the npm globals isn't in the Windows PATHor NODE_PATHenvironment variables.
根据您使用的目录\AppData\Roaming,您使用的是 Windows 并且此错误通常是因为 npm 全局变量的路径不在 WindowsPATH或NODE_PATH环境变量中。
Use SETto check the values you are using for the paths and if your npm directory isn't listed, that will be the issue.
使用SET来检查你正在使用的路径,如果未列出您的NPM目录中的值,这将是问题。
If you don't want npm to save to this directory, check the npm configuration optionsand the npm folders docsto see what you can change in this regard...
回答by Neha
'karma' is not recognized as an internal or external command, operable program or batch file.
'karma' 不是内部或外部命令,也不是可运行的程序或批处理文件。
If the above mentioned solution does not work, than The cause of issue is previous version of nodejs. So uninstall the previous version of nodejs and re-install the latest version.It will resolve your issue. As I faced the same and by doing above changes it worked for me.
如果上述解决方案不起作用 ,则问题的原因是以前版本的 nodejs。所以卸载之前版本的nodejs,重新安装最新版本。它将解决您的问题。当我面临同样的情况时,通过进行上述更改,它对我有用。
Thanks.
谢谢。
回答by Maksood
Official documentation at https://karma-runner.github.io/0.12/intro/installation.htmlis confusing. It implies that npm install -g karma-cli is to install karma globally but it actually required for to run karma from command line.
https://karma-runner.github.io/0.12/intro/installation.html上的官方文档令人困惑。这意味着 npm install -g karma-cli 是全局安装 karma 但它实际上需要从命令行运行 karma。
回答by user8082924
I had same: 'karma' is not recognized as an internal or external command, operable program or batch file.problem when i tried to install it directly to my project file. When i used npm install -g karma-clito global install everything worked just fine.
我有同样的'karma' is not recognized as an internal or external command, operable program or batch file.问题:当我尝试将它直接安装到我的项目文件时出现问题。当我习惯于npm install -g karma-cli全局安装时,一切正常。

