Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pro: Cannot read property 'deploy' of undefined #2136

Closed
DavidTalamona opened this issue Nov 18, 2017 · 9 comments
Closed

Pro: Cannot read property 'deploy' of undefined #2136

DavidTalamona opened this issue Nov 18, 2017 · 9 comments

Comments

@DavidTalamona
Copy link

DavidTalamona commented Nov 18, 2017

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/

Current behavior:
When using the ionic native package for "pro" with version 4.2.2 (latest at the moment) live reload as well as ionic serve fail with error Cannot read property 'deploy' of undefined

Expected behavior:
No error ;o)

Steps to reproduce:
Simply include the plugin and the native package in some app. Don't even have to actively use it. The error ocurrs on initialization of the package.

Related code:
Temporarily fixed it by changing node_modules -> @ionic-native -> pro -> index.js line 153 from
_this.deploy = new ProDeploy(Pro_1.getPlugin()).deploy);
into
_this.deploy = new ProDeploy((Pro_1.getPlugin() || {}).deploy);

Looks like some fallback must be there if the plugin itself is not present!

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

cli packages: (C:\www\localhost\touch\ionic2\PLC\PlusCash\node_modules)

    @ionic/cli-utils  : 1.18.0
    ionic (Ionic CLI) : 3.18.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.0
    Cordova Platforms  : android 6.4.0 ios 4.5.3
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 25.2.5
    Node              : v6.11.3
    npm               : 4.6.0
    OS                : Windows 10

Environment Variables:

    ANDROID_HOME : C:\Program Files (x86)\Android\android-sdk

Misc:

    backend : pro
@ibcooley
Copy link

I'm also experiencing this problem. It occurs for me on IOS.

@ibcooley
Copy link

@DavidTalamona Are you sure it isn't, for some reason, that the cordova-plugin-ionic isnt registering properly on your device? I'm running into the same issue, and the more I think about it -- i feel like cordova-plugin-ionic is not registering properly.

@DavidTalamona
Copy link
Author

@ibcooley I'm sure it's a bug in the TS plugin wrapper.
I solved it by cloning the file of IONIC, fixing it and importing my file instead of the one from IONIC.
I named it ionic-native-pro-fixed.ts and therefore the necessary includes have to be modified from import {Pro as IonicPro} from '@ionic-native/pro'; to import {Pro as IonicPro} from './ionic-native-pro-fixed';.

The file itself looks like this:

// todo: remove after the changes in GIT history are fixed on the original an then change all includes of this file to: @ionic-native/pro

import { Injectable } from '@angular/core';
import { Plugin, Cordova, CordovaInstance, IonicNativePlugin } from '@ionic-native/core';
import { Observable } from 'rxjs/Observable';

/**
 * Information about the currently running app
 */
export interface AppInfo {
  platform: string;
  platformVersion: string;
  version: string;
  bundleName: string;
  bundleVersion: string;
}

/**
 * Information about the current live update
 */
export interface DeployInfo {
  deploy_uuid: string;
  channel: string;
  binary_version: string;
}

/**
 * Object for manually configuring deploy
 */
export interface DeployConfig {
  appId?: string;
  host?: string;
  channel?: string;
}

/**
 * @hidden
 */
export class ProDeploy {

  constructor(private _objectInstance: any) { window['dummy'] = this._objectInstance; }

  /**
   * Re-initialize Deploy plugin with a new App ID and host.  Not used in most cases.
   * @param config A valid Deploy config object
   */
  @CordovaInstance()
  init(config: DeployConfig): Promise<any> { return; }

  /**
   * Check a channel for an available update
   * @return {Promise<string>} Resolves with 'true' or 'false', or rejects with an error.
   */
  @CordovaInstance()
  check(): Promise<string> { return; }

  /**
   * Download an available version
   * @return {Observable<any>} Updates with percent completion, or errors with a message.
   */
  @CordovaInstance({
    observable: true
  })
  download(): Observable<any> { return; }

  /**
   * Unzip the latest downloaded version
   * @return {Observable<any>} Updates with percent completion, or errors with a message.
   */
  @CordovaInstance({
    observable: true
  })
  extract(): Observable<any> { return; }

  /**
   * Reload app with the deployed version
   */
  @CordovaInstance()
  redirect(): Promise<any> { return; }

  /**
   * Get info about the version running on the device
   * @return {Promise<DeployInfo>} Information about the current version running on the app.
   */
  @CordovaInstance()
  info(): Promise<DeployInfo> { return; }

  /**
   * List versions stored on the device
   */
  @CordovaInstance()
  getVersions(): Promise<any> { return; }

  /**
   * Delete a version stored on the device by UUID
   * @param version A version UUID
   */
  @CordovaInstance()
  deleteVersion(version: string): Promise<any> { return; }
}

/**
 * @name Pro
 * @description
 * This plugin enables Ionic Pro services like live updates and error monitoring
 *
 * @usage
 * ```typescript
 * import { Pro, AppInfo, DeployInfo } from '@ionic-native/pro';
 *
 *
 * constructor(private pro: Pro) { }
 *
 * // Get app info
 * this.pro.getAppInfo().then((res: AppInfo) => {
 *   console.log(res)
 * })
 *
 * // Get live update info
 * this.pro.deploy.info().then((res: DeployInfo) => {
 *   console.log(res)
 * })
 * ```
 */
@Plugin({
  pluginName: 'Pro',
  plugin: 'cordova-plugin-ionic',
  pluginRef: 'IonicCordova',
  repo: 'https://github.com/ionic-team/cordova-plugin-ionic',
  platforms: ['Android', 'iOS'],
  install: 'ionic cordova plugin add cordova-plugin-ionic --save --variable APP_ID="XXXXXXXX" --variable CHANNEL_NAME="Channel"'
})
@Injectable()
export class Pro extends IonicNativePlugin {
  /**
   * Ionic Pro Deploy .js API.
   */
  deploy: ProDeploy = new ProDeploy((Pro.getPlugin() || {}).deploy);

  /**
   * Not yet implemented
   * @return {Promise<any>} Returns a promise that resolves when something happens
   */
  @Cordova()
  enableCrashLogging(): Promise<any> { return; }

  /**
   * Not yet implemented
   * @return {Promise<any>} Returns a promise that resolves when something happens
   */
  @Cordova()
  checkForPendingCrash(): Promise<any> { return; }

  /**
   * Not yet implemented
   * @return {Promise<any>} Returns a promise that resolves when something happens
   */
  @Cordova()
  loadPendingCrash(): Promise<any> { return; }

  /**
   * Not yet implemented
   * @return {Promise<any>} Returns a promise that resolves when something happens
   */
  @Cordova()
  forceCrash(): Promise<any> { return; }

  /**
   * Get information about the currently running app
   * @return {Promise<any>} Returns a promise that resolves with current app info
   */
  @Cordova()
  getAppInfo(): Promise<AppInfo> { return; }
}

With this fix everything works as expected!

@Maistho
Copy link
Contributor

Maistho commented Dec 19, 2017

@Maistho
Copy link
Contributor

Maistho commented Jan 21, 2018

Seems like this is fixed on the v5 branch tho. Would be nice to get a release that contains that fix before v5. (Or just a v5 release soon™️)

@ibcooley
Copy link

ibcooley commented Jan 21, 2018 via email

@Maistho
Copy link
Contributor

Maistho commented Jan 21, 2018

@ihadeed probably knows more about the v5 ETA

@mlynch
Copy link
Collaborator

mlynch commented Jan 25, 2018

Hi all, thanks for the tips here. Can you try version 4.5.3 of @ionic-native/pro? Both of these issues should be resolved.

@mlynch mlynch closed this as completed Jan 25, 2018
@Maistho
Copy link
Contributor

Maistho commented Jan 26, 2018

Looks like it's resolved, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants