You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ionic3+Angular5/CLI7调用图库图片失败求助

Ionic 3 + Angular 5: getPicture Fails with "cordova is not a function" Error, Plus DevApp Plugin Issue

Problem Description

I'm working on a project built with Ionic 3, Angular CLI 7, and Angular 5, and I'm unable to retrieve images from the photo gallery. When calling the getPicture method (either via @ionic-native/image-picker or @ionic-native/camera), I get this error:

Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"]) is not a function. (In ‘Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"])(this, "getPicture", { "callbackOrder": "reverse" }, arguments)’, ‘Object(WEBPACK_IMPORTED_MODULE_1__ionic_native_core["cordova"])’ is an instance of Object)

Code Snippets

ImagePicker Implementation:

let options = { maximumImagesCount: 1 };
this.imagePicker.getPictures(options).then((results) => {
  for (var i = 0; i < results.length; i++) {
    this.imgPreview = results[i];
    this.base64.encodeFile(results[i]).then((base64File: string) => {
      this.regData.avatar = base64File;
    }, (err) => { });
  }
}, (err) => { console.log(err); });

Camera Implementation:

var sourceType = this.camera.PictureSourceType.PHOTOLIBRARY;
var options = { quality: 100, sourceType: this.camera.PictureSourceType.PHOTOLIBRARY, saveToPhotoAlbum: false, correctOrientation: true };
this.camera.getPicture(options).then((imagePath) => {
  console.log("Img path: " + imagePath);
  if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
    this.filePath.resolveNativePath(imagePath)
      .then(filePath => {
        let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
        let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
      });
  } else {
    var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
    var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
  }
}, (err) => { console.log(err); });

Steps Already Tried

  • Upgraded all native plugins to version 5.0.0-beta.15 — no improvement.
  • Downgraded @ionic-native/image-picker and @ionic-native/base64 to match the version of @ionic-native/core — this seemed to fix the original "cordova is not a function" error, but now when running via Ionic DevApp, I get a plugin_not_installed error even though the telerik-imagepicker plugin is already added to Cordova.

Note

I had to step away from the project temporarily and haven't had a chance to test the solution suggested by Sergey yet. I'm hoping to get more guidance to resolve this fully.


内容的提问来源于stack exchange,提问作者Mary

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:20:24