错误:ENOENT:运行 Ionic Cordova 平台添加 Android 时没有此类文件或目录

Que*_*ker 13 android cordova ionic-framework wonderpush ionic5

我只是不知道如何解决这个问题。我尝试了很多解决方案,但对我的情况没有任何作用。所以我将我的项目放入xampp\htdocs文件夹名称中exam-ionic

然后当我尝试添加平台 android 时出现错误

Error: ENOENT: no such file or directory, 
 open 'c:\xampp\htdocs\exam-ionic\android\package.json'] {
 errno: -4058,
 code: 'ENOENT',
 syscall: 'open',
 path: 'c:/xampp/htdocs/exam-ionic/android/package.json
Run Code Online (Sandbox Code Playgroud)

这是我跑步的时候ionic cordova platform add android --verbose

ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 1 functions +2ms
ionic:utils-process error while killing process tree for 6724: Error: Command 
failed: taskkill /pid 
6724 /T /F
ionic:utils-process ERROR: The process "6724" not found.
ionic:utils-process
ionic:utils-process     at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process     at ChildProcess.emit (events.js:315:20)
ionic:utils-process     at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process     at Process.ChildProcess._handle.onexit 
(internal/child_process.js:288:5) {
ionic:utils-process   killed: false,
ionic:utils-process   code: 128,
ionic:utils-process   signal: null,
ionic:utils-process   cmd: 'taskkill /pid 6724 /T /F'
ionic:utils-process } +916ms
ionic:utils-process onBeforeExit handler: error from function: Error: Command 
failed: taskkill /pid 
6724 /T /F
ionic:utils-process ERROR: The process "6724" not found.
ionic:utils-process
ionic:utils-process     at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process     at ChildProcess.emit (events.js:315:20)
ionic:utils-process     at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process     at Process.ChildProcess._handle.onexit 
(internal/child_process.js:288:5) {
ionic:utils-process   killed: false,
ionic:utils-process   code: 128,
ionic:utils-process   signal: null,
ionic:utils-process   cmd: 'taskkill /pid 6724 /T /F'
ionic:utils-process } +3ms
ionic:utils-process processExit: exiting (exit code: 1) +5ms
Run Code Online (Sandbox Code Playgroud)

这是我的离子信息

Ionic:

Ionic CLI                     : 5.4.16 
(C:\Users\User\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework               : @ionic/angular 5.6.0
@angular-devkit/build-angular : 0.1101.4
@angular-devkit/schematics    : 11.1.4
@angular/cli                  : 11.1.4
@ionic/angular-toolkit        : 3.1.0

Capacitor:

Capacitor CLI   : 2.4.7
@capacitor/core : 2.4.7

Cordova:

Cordova CLI       : 10.0.0
Cordova Platforms : none
Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin- 
ionic-webview 4.2.1, (and 9 other plugins)

Utility:

cordova-res : 0.15.3
native-run  : 1.3.0

System:

Android SDK Tools : 26.1.1 (C:\Users\User\AppData\Local\Android\Sdk)
NodeJS            : v14.16.1 (C:\Program Files\nodejs\node.exe)
npm               : 7.9.0
OS                : Windows 10
Run Code Online (Sandbox Code Playgroud)

这是 package.json

Error: ENOENT: no such file or directory, 
 open 'c:\xampp\htdocs\exam-ionic\android\package.json'] {
 errno: -4058,
 code: 'ENOENT',
 syscall: 'open',
 path: 'c:/xampp/htdocs/exam-ionic/android/package.json
Run Code Online (Sandbox Code Playgroud)

我尝试重新安装 npm,重新安装 cordova,更新 ionic CLI,删除node_module文件夹 + package.lock.jsonthen npm install,但没有任何效果。请帮助meeee

小智 22

我运行时遇到同样的错误,今天我找到了解决方案。过去,我尝试过电容器插件,但我的项目是cordova,所以我将其从我的项目中删除了。但我认为某些文件没有正确删除,当我运行离子修复时,问题开始了。因此,为了修复此问题,我删除了项目根目录下的 ANDROID 文件夹以及根目录下与 Capacitor 相关的所有文件,编辑了 package.json 并删除了与 Capacitor 相关的所有内容,然后一切再次正常工作。

解决方案

  1. 删除android项目根目录下的文件夹
  2. 编辑package.json并删除与相关的所有内容Capacitor