Android 如何修复 Windows 命令提示符中无法识别“cordova”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21901999/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:17:15  来源:igfitidea点击:

How to fix 'cordova' is not recognized in the Windows command prompt

androidwindowscordova

提问by Roshdy

ERROR

错误

C:\>cordova

'cordova' is not recognized as an internal or external command,
operable program or batch file.

My Environment Path

我的环境路径

C:\>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\cmd
;C:\Program Files (x86)\GtkSharp.12\bin;C:\Program Files (x86)\Windows Kits.
1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server0\Tools\B
inn\;C:\Program Files\Microsoft\Web Platform Installer\;**C:\Program Files\ANT\apa
che-ant-1.9.3\bin;C:\Program Files\Java\jdk1.7.0_51\bin;C:\Development\sdk\tools
;C:\Development\sdk\platform-tools;C:\Development\cordova-3.3.0\cordova-android\
bin;**

NB:I have read every available tutorial, followed at least 10 of them, read all the similar questions about 'phonegap' not recognized,, .etc. I have my 'Enabled'registry set to 1 as some solutions have suggested, re-installed 'phonegap'& 'cordova'through NPM install -g phonegap, and same for 'cordova', and I still can't get them to run.

注意:我已经阅读了所有可用的教程,至少关注了其中的 10 个,阅读了所有关于'phonegap' not recognized,, . 等的类似问题。我将我的“已启用”注册表设置为 1,因为某些解决方案已建议重新安装'phonegap''cordova'通过NPM install -g phonegap,并且与 相同'cordova',但我仍然无法让它们运行。

I copied an old phonegap application that I made on another PC, and I can run it through just fine. Hope this would clear anything up.

我复制了我在另一台 PC 上制作的旧 phonegap 应用程序,我可以很好地运行它。希望这会清除任何事情。

回答by QuickFix

You do not need to add any cordova folder to the path.

您不需要将任何cordova 文件夹添加到路径中。

cordova command is a nodejs npm script, what you need is to have the npm folder in your path :

cordova 命令是一个 nodejs npm 脚本,你需要的是在你的路径中有 npm 文件夹:

%appdata%\npm\

or if it does not work, use instead

或者如果它不起作用,请改用

c:\users\YourUserName\AppData\Roaming\npm\

(replace YourUserName with the name of your user profile)

(将 YourUserName 替换为您的用户配置文件的名称)

What's strange is that I don't remember I had to change it manually, I think it should be added automatically when installing node and npm.

奇怪的是,我不记得我必须手动更改它,我认为应该在安装node和npm时自动添加它。

回答by Vikram Palakurthi

npm install -g cordova

-g is a global install option and it will make the cordova globally available in AppData\Roaming\npm. Restart the prompt if necessary.

-g 是一个全局安装选项,它将使 Cordova 在 AppData\Roaming\npm 中全局可用。如有必要,重新启动提示。

回答by Kartik Arora

The Method below is the solution of every such problem related to npm, Be it Phonegap, Cordova, Ionic or else... The concept is that every software installed using npm is saved on this path:

下面的方法是与 npm 相关的所有此类问题的解决方案,无论是Phonegap、Cordova、Ionic 还是其他……其概念是使用 npm 安装的每个软件都保存在此路径上:

C:\Users\[Your User Name]\AppData\Roaming\npm

So, what we are going to do is just adding the above path to Windows Environment Variable. If you are a begineer, the steps for adding path are as follows:

所以,我们要做的只是将上述路径添加到 Windows 环境变量中。如果您是初学者,添加路径的步骤如下:

  1. Go to Control Panel.
  2. Under All Control Panel Items, Go to System.
  3. Click on the Advanced system settingsoptions in the Sidebar.
  4. The System PropertiesDialog Box will appear.
  1. 转到控制面板
  2. 在所有控制面板项目下,转到系统
  3. 单击边栏中的高级系统设置选项。
  4. 系统属性对话框将会出现。

You would have done the so far work through searching "Edit Environment Variables" in Search Bar :).

您可以通过在搜索栏中搜索“编辑环境变量”来完成到目前为止的工作:)。

  1. Now, In the System Properties dialog box, there will be AdvancedTab.
  2. In Advanced tab, there will be an option Environment Variables...
  3. Click on it, this will open another Dialog box for Environment Variables.
  4. In System variables, Select Pathas shown in image link, and click Edit...

    Path attribute in System Variables

  5. Copy the above path, and add it here as shown in link Copy the Path

  6. Here, you should make sure that the 2 different paths are always seperated by a semicolon ;. Keeping this in mind, add your path to the existing paths.
  1. 现在,在“系统属性”对话框中,将出现“高级”选项卡。
  2. 在高级选项卡中,将有一个选项环境变量...
  3. 单击它,这将打开另一个环境变量对话框。
  4. System variables 中,选择Path如图链接所示,然后单击Edit...

    系统变量中的路径属性

  5. 复制上述路径,并将其添加到此处,如链接 复制路径所示

  6. 在这里,您应该确保 2 个不同的路径始终用分号分隔. 牢记这一点,将您的路径添加到现有路径。

This will make the application run globally. This is the General Algorithm of steps employed for any type of Path Configuration. If You have any issues left, please feel free to ask.

这将使应用程序全局运行。这是用于任何类型的路径配置的步骤的通用算法。如果您还有任何问题,请随时提出。

回答by P Manishankar

Try running Command Prompt as an administrator..It worked for me

尝试以管理员身份运行命令提示符..它对我有用

回答by user2243301

Try restarting the command prompt window. It worked for me.

尝试重新启动命令提示符窗口。它对我有用。

回答by Leon Africa

Issue is probably with location of node/npm.

问题可能与节点/npm 的位置有关。

npm working? say npm clear cache

npm 工作?说 npm 清除缓存

Then even if its not working go to Environment Variables. Ensure nodejs is directed to its directory(wherever you installed it)and npm(which is in Users/YourUsername/AppData/roaming) .. its a hidden folder.

然后,即使它不起作用,也请转到环境变量。确保 nodejs 被定向到它的目录(无论你在哪里安装)和 npm(在用户/你的用户名/AppData/roaming 中)......它是一个隐藏文件夹。

The run npm install npm -g OR (if and only if) that gives issues npm install npm@latest

运行 npm install npm -g 或(当且仅当)给出问题 npm install npm@latest

I recommend getting bower too , so say npm install -g bower

我也建议使用 bower ,所以说 npm install -g bower

Finally npm install -g cordova

最后 npm install -g cordova

There you go!

你去吧!

回答by PSK

Place java path before ant path. change the path according to your paths.

将 java 路径放在 ant 路径之前。根据您的路径更改路径。

C:\Program Files\Java\jdk1.6.0_20\bin;D:\apache-ant-1.9.3\bin;D:\adt-bundle-windows-x86\sdk\tools;D:\adt-bundle-windows-x86\sdk\platform-tools;C:\Program Files\nodejs\;C:\Program Files\Git\cmd

回答by racerkrish

I had an issue with the default directories that are used by npm. You can get this list by typing 'npm config list' in the command prompt. In my case, for some reason, the cordova installation was going inside a '=' directory. My Command Prompt pointed me to a 'npm.mrc' file inside 'C:\Users\USERNAME' folder when I typed 'npm config list' from where it is picking up the '=' folder inside 'C:\Users\USERNAME\=' as the default folder for cordova. When I uninstalled node, deleted both the 'npm.mrc' file and the '=' folder and reinstalled node and cordova, this issue disappeared. Hope this helps.

我对 npm 使用的默认目录有问题。您可以通过在命令提示符下键入“npm config list”来获取此列表。就我而言,出于某种原因,cordova 安装进入了“=”目录。当我输入“npm config list”时,我的命令提示符将我指向“C:\Users\USERNAME”文件夹中的“npm.mrc”文件,该文件从“C:\Users\USERNAME”中的“=”文件夹中提取\=' 作为cordova 的默认文件夹。当我卸载节点,删除“npm.mrc”文件和“=”文件夹并重新安装节点和cordova时,这个问题就消失了。希望这可以帮助。

回答by Jayanta

I have visual studio installed on my system. Cordova got installed under the following location:

我的系统上安装了 Visual Studio。Cordova 安装在以下位置:

C:\ProgramData\Microsoft\VisualStudio\MDA\c33fb238\taco-toolset-6.3.1

C:\ProgramData\Microsoft\VisualStudio\MDA\c33fb238\taco-toolset-6.3.1

I had to manually add this to PATH.

我不得不手动将其添加到 PATH。

To know the path where cordova is installed run npm install -g cordovaagain and the path will be printed on the screen.

要知道安装cordova 的路径,npm install -g cordova再次运行,该路径将打印在屏幕上。

回答by Mahendra

Open a Command prompt in Run as administrator mode and run the below install command

在以管理员身份运行模式下打开命令提示符并运行以下安装命令

 npm install -g cordova

Now check if the command is now recognized. (if needed restart the command prompt)

现在检查命令现在是否被识别。(如果需要重新启动命令提示符)

Now in the visual studio code

现在在 Visual Studio 代码中

  1. goto the terminal
  2. Navigate to the cordova folder
  3. Run the usual commands

    cordova platform add android

    cordova run android

  1. 转到终端
  2. 导航到cordova文件夹
  3. 运行常用命令

    科尔多瓦平台添加android

    科尔多瓦运行安卓