“ path”参数必须为字符串类型。收到的类型对象-Cordova + Angular

时间:2020-04-27 13:00:40

标签: android angular cordova

我正在从以前创建的角度应用程序创建移动应用程序。我使用过this教程,该教程说明了如何使用cordova从angular创建本地应用程序。我执行了以下步骤:

  • 已安装cordova
  • 添加了环境变量
  • 已将Cordova添加到应用程序中
  • 使用cordova create mobile创建了cordova应用,该应用在<myprojectpath>/mobile中创建了cordova项目
  • 创建了一个软链接www,该链接重定向到应用程序的dist文件夹
  • 将android添加为平台(使用sudo权限,否则无法执行操作)
  • 创建的版本
  • 使用cordova requirements检查了需求,以查看是否缺少任何内容
  • 在终端中运行了cordova run android(使用了sudo权限,否则无法执行此操作)

它给了我以下错误:

“ path”参数必须为字符串类型。收到类型对象

在错误发生之前提供以下信息

Checking Java JDK and Android SDK versions  
ANDROID_SDK_ROOT=undefined (recommended setting)  
ANDROID_HOME=/home/<usr>/Android/Sdk (DEPRECATED)  
No target specified and no devices found, deploying to emulator  
No emulator specified, defaulting to Pixel_API_28

添加--verbose给了我以下内容:

The "path" argument must be of type string. Received type object
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
    at validateString (internal/validators.js:112:11)
    at Object.dirname (path.js:1129:5)
    at /var/www/html/employee_portal/mobile/platforms/android/cordova/lib/emulator.js:294:37
    at _fulfilled (/var/www/html/employee_portal/mobile/node_modules/q/q.js:854:54)
    at /var/www/html/employee_portal/mobile/node_modules/q/q.js:883:30
    at Promise.promise.promiseDispatch (/var/www/html/employee_portal/mobile/node_modules/q/q.js:816:13)
    at /var/www/html/employee_portal/mobile/node_modules/q/q.js:624:44
    at runSingle (/var/www/html/employee_portal/mobile/node_modules/q/q.js:137:13)
    at flush (/var/www/html/employee_portal/mobile/node_modules/q/q.js:125:13)
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

我已经检查了一些关于stackoverflow的问题,这些问题指向与离子相关的类似问题,例如undefined path errorpath error after upgrade,但是我无法使用这些解决方案解决它们。我不确定为什么会这样,因为当我运行cordova build时,它创建的apk没有任何问题。

我也尝试过删除node_modules文件夹,并在我的mobile文件夹中运行npm install,但是没有帮助。

我不确定为什么会导致此错误以及如何解决该问题

cordova requirements的结果:

Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28,android-27
Gradle: installed /opt/gradle/gradle-5.2.1/bin/gradle

平台版本:

Installed platforms:
  android 8.1.0
Available platforms: 
  browser ^6.0.0
  electron ^1.0.0
  ios ^5.0.0
  osx ^5.0.0
  windows ^7.0.0
我的cordova项目的

package.json

{
  "name": "helloworld",
  "displayName": "HelloCordova",
  "version": "1.0.0",
  "description": "A sample Apache Cordova application that responds to the deviceready event.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "ecosystem:cordova"
  ],
  "author": "Apache Cordova Team",
  "license": "Apache-2.0",
  "dependencies": {
    "cordova-android": "^8.1.0"
  },
  "devDependencies": {
    "cordova-plugin-whitelist": "^1.3.4"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {}
    },
    "platforms": [
      "android"
    ]
  }
}

1 个答案:

答案 0 :(得分:0)

已解决:深入研究后,我发现Cordova无法启动模拟器,这就是为什么我寻找解决方法并得到here的原因,该问题要求手动启动使用android studio仿真器,然后运行构建。像魅力一样工作。