错误“cordova\version 未被识别为内部或外部命令、可操作程序或批处理文件”

Hér*_*oso 8 cordova ionic-framework cordova-plugins

当我执行命令 ionic cordova prepare android 时,我收到此错误:

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

    at ChildProcess.exithandler (node:child_process:397:12)
    at ChildProcess.emit (node:events:390:28)
    at maybeClose (node:internal/child_process:1064:16)
    at Socket.<anonymous> (node:internal/child_process:450:11)
    at Socket.emit (node:events:390:28)
    at Pipe.<anonymous> (node:net:687:12) {
  killed: false,
  code: 1,
  signal: null,
  cmd: '"C:\\Programacao\\appMalote216\\platforms\\android\\cordova\\version"'
}
[ERROR] An error occurred while running subprocess cordova.
Run Code Online (Sandbox Code Playgroud)

我在尝试满足 Google Play 新的 API 级别定位政策时遇到了这个问题。当我创建 android@9 平台时,我可以正常运行命令,甚至生成签名的 apk,当我在发出准备命令时添加 android@10 平台时,我收到此错误。

开发环境配置:

Ionic:

   Ionic CLI                     : 6.18.1 (C:\Users\micro-85\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 5.9.3
   @angular-devkit/build-angular : 0.1000.8
   @angular-devkit/schematics    : 10.0.8
   @angular/cli                  : 10.0.8
   @ionic/angular-toolkit        : 2.3.3

Cordova:

   Cordova CLI       : 11.0.0
   Cordova Platforms : android 10.1.1
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 20 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.5.0

System:

   Android SDK Tools : 26.1.1 (C:\Users\micro-85\AppData\Local\Android\Sdk)
   NodeJS            : v16.13.2 (C:\Program Files\nodejs\node.exe)
   npm               : 8.4.0
   OS                : Windows 10

Node:v16.13.2
NPM: 8.4.0
Gradle: 7.3.3
Run Code Online (Sandbox Code Playgroud)

类似问题:https ://github.com/OneSignal/OneSignal-Cordova-SDK/issues/725

Sté*_*ane 5

我在 Windows 上也遇到了同样的问题。问题是 Windows CMD 不会将文件platforms/android/cordova/version 识别为命令,即使它存在。(因为它是一个 bash 脚本)。

  1. 解决方案1

您可以通过创建将运行节点脚本版本的.bat文件来修复它。

例如,使用以下内容创建.batplatforms/android/cordova/version.bat :

node %~dpnx0
Run Code Online (Sandbox Code Playgroud)
  1. 解决方案 2:如果您安装了 bash,并且在使用 npm 运行脚本时出现此错误,您可以将 npm 配置为使用 git bash 而不是 Windows CMD。

    npm 配置设置 script-shell ""

例如

npm config set script-shell "C:\\Program Files\\Git\\usr\\bin\\bash.exe" 
Run Code Online (Sandbox Code Playgroud)