ionic-team / ionic-cli

The Ionic command-line interface
MIT License
2k stars 653 forks source link

Cannot build in android in --prod mode #2628

Open jgw96 opened 7 years ago

jgw96 commented 7 years ago

From @lostdev on August 9, 2017 18:1

Ionic version: (check one with "x") [ ] 1.x (For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1) [ ] 2.x [x] 3.x

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 http://ionicworldwide.herokuapp.com/

Current behavior: When building my project using ionic cordova build android --prod I get the following error:

Running app-scripts build: --build --prod --iscordovaserve --nobrowser

[11:04:29]  build prod started ...
[11:04:29]  clean started ...
[11:04:29]  clean finished in 2 ms
[11:04:29]  copy started ...
[11:04:29]  ngc started ...
[11:04:38]  ngc finished in 8.64 s
[11:04:38]  preprocess started ...
[11:04:38]  deeplinks started ...
[11:04:38]  deeplinks finished in 30 ms
[11:04:38]  optimization started ...
[11:04:38]  copy finished in 8.86 s
[11:04:50]  optimization finished in 11.55 s
[11:04:50]  preprocess finished in 11.58 s
[11:04:50]  webpack started ...
[WARN] Error occurred during command execution from a CLI plugin
       (@ionic/cli-plugin-cordova).
Error: ./node_modules/ionic-native/dist/esm/plugins/plugin.js
Module build failed: TypeError: Cannot read property 'type' of undefined
    at Object.getEffectiveTypeAnnotationNode (C:\git\mobile\node_modules\typescr
ipt\lib\typescript.js:9341:17)
    at assignContextualParameterTypes (C:\git\mobile\node_modules\typescript\lib
\typescript.js:41652:25)
    at checkFunctionExpressionOrObjectLiteralMethod (C:\git\mobile\node_modules\
typescript\lib\typescript.js:41948:29)
    at checkExpressionWorker (C:\git\mobile\node_modules\typescript\lib\typescri
pt.js:42959:28)
    at checkExpression (C:\git\mobile\node_modules\typescript\lib\typescript.js:
42898:42)
    at checkExpressionCached (C:\git\mobile\node_modules\typescript\lib\typescri
pt.js:42779:38)
    at checkReturnStatement (C:\git\mobile\node_modules\typescript\lib\typescrip
t.js:45418:54)
    at checkSourceElement (C:\git\mobile\node_modules\typescript\lib\typescript.
js:46763:28)
    at Object.forEach (C:\git\mobile\node_modules\typescript\lib\typescript.js:1
506:30)
    at checkBlock (C:\git\mobile\node_modules\typescript\lib\typescript.js:44563
:16)
 @ ./node_modules/ionic-native/dist/esm/index.js 146:0-33
 @ ./src/providers/network-status.ts
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts

Expected behavior: I expect the build to work, just like it does without the --prod flag.

Steps to reproduce: I cannot provide specific steps, but it started occurring after a recent update of the ionic CLI. After looking more in detail, the error is caused by a JSDoc comment in node_modules\ionic-native\dist\esm\plugins\plugin.js. The following are two versions of the JSDoc. The original (non-working), and my updated, which fixes the issue:

Original code:

/**
 * @private
 * @param pluginObj
 * @param methodName
 * @param opts
 * @returns {function(...[any]): (undefined|*|Observable|*|*)}
 */
export var wrap = function (pluginObj, methodName, opts) {
-- line 245

Fixed code (notice the ... missing)

/**
 * @private
 * @param pluginObj
 * @param methodName
 * @param opts
 * @returns {function([any]): (undefined|*|Observable|*|*)}
 */
export var wrap = function (pluginObj, methodName, opts) {
-- line 245

Other information: My question on the Ionic forum: https://forum.ionicframework.com/t/error-ionic-native-dist-esm-plugins-plugin-js-module-build-failed-typeerror-cannot-read-property-type-of-undefined/101191/8 Another person with the same issue https://forum.ionicframework.com/t/error-during-executing-ionic-cordova-run-android-prod/100252/6 Seems to be an issue with the angular CLI? https://github.com/angular/angular-cli/issues/7110

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

C:\git\mobile>ionic info

cli packages: (C:\git\mobile\node_modules)

    @ionic/cli-plugin-cordova       : 1.6.2
    @ionic/cli-plugin-ionic-angular : 1.4.1
    @ionic/cli-utils                : 1.7.0
    ionic (Ionic CLI)               : 3.7.0

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts : 2.1.3
    Cordova Platforms  : android 6.2.3 ios 4.3.1
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 25.2.5
    Node              : v6.10.3
    OS                : Windows 8.1
    npm               : 3.10.8

tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": false,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*spec.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

package.json:

{
    "name": "App",
    "version": "0.0.1",
    "description": "App",
    "license": "Apache-2.0",
    "scripts": {
        "build": "ionic-app-scripts build",
        "clean": "ionic-app-scripts clean",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve",
        "test": "karma start ./.tests/karma.conf.js",
        "test-ci": "karma start ./.tests/karma.conf.js --single-run"
    },
    "dependencies": {
        "@angular/animations": "^4.3.1",
        "@angular/common": "^4.3.1",
        "@angular/compiler": "^4.3.1",
        "@angular/compiler-cli": "^4.3.1",
        "@angular/core": "^4.3.1",
        "@angular/forms": "^4.3.1",
        "@angular/http": "^4.3.1",
        "@angular/platform-browser": "^4.3.1",
        "@angular/platform-browser-dynamic": "^4.3.1",
        "@angular/platform-server": "^4.3.1",
        "@angular/router": "^4.3.1",
        "@ionic-native/app-version": "^4.1.0",
        "@ionic-native/core": "3.10.2",
        "@ionic-native/in-app-browser": "3.10.2",
        "@ionic-native/splash-screen": "3.10.2",
        "@ionic-native/status-bar": "3.10.2",
        "@ionic/storage": "2.0.1",
        "@types/pouchdb": "^5.4.28",
        "@types/pouchdb-browser": "^5.4.4",
        "@types/pouchdb-core": "^5.4.5",
        "@types/semver": "^5.3.32",
        "chart.js": "^2.6.0",
        "cordova-android": "^6.2.3",
        "cordova-ios": "^4.3.1",
        "cordova-plugin-app-version": "^0.1.9",
        "cordova-plugin-console": "1.0.5",
        "cordova-plugin-crosswalk-webview": "~2.2.0",
        "cordova-plugin-device": "1.1.4",
        "cordova-plugin-inappbrowser": "~1.4.0",
        "cordova-plugin-splashscreen": "~4.0.1",
        "cordova-plugin-statusbar": "2.2.1",
        "cordova-plugin-whitelist": "1.3.1",
        "cordova-plugin-wkwebview-engine": "git+https://github.com/ionic-team/cordova-plugin-wkwebview-engine.git",
        "enquire.js": "^2.1.6",
        "events": "^1.1.1",
        "ionic-angular": "^3.5.3",
        "ionic-plugin-keyboard": "~2.2.1",
        "ionicons": "3.0.0",
        "pouchdb": "^5.4.5",
        "pouchdb-browser": "^6.0.6",
        "pouchdb-upsert": "^2.0.2",
        "rxjs": "^5.4.2",
        "semver": "^5.4.1",
        "sw-toolbox": "3.4.0",
        "typescript": "^2.4.2",
        "zone.js": "0.8.11"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^2.1.3",
        "@ionic/cli-plugin-cordova": "1.6.2",
        "@ionic/cli-plugin-ionic-angular": "1.4.1",
        "@types/jasmine": "^2.5.53",
        "angular2-template-loader": "^0.6.2",
        "html-loader": "^0.4.5",
        "ionic": "3.7.0",
        "jasmine-core": "^2.7.0",
        "jasmine-spec-reporter": "^4.1.0",
        "karma": "^1.7.0",
        "karma-chrome-launcher": "^2.2.0",
        "karma-jasmine": "^1.1.0",
        "karma-sourcemap-loader": "^0.3.7",
        "karma-webpack": "^2.0.4",
        "null-loader": "^0.1.1",
        "protractor": "^5.1.1",
        "ts-loader": "^2.0.3",
        "ts-node": "^3.0.2",
        "typescript": "2.3.3"
    },
    "config": {},
    "cordova": {
        "platforms": [
            "android",
            "ios"
        ],
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-crosswalk-webview": {
                "XWALK_VERSION": "22+",
                "XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
                "XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
                "XWALK_MODE": "embedded",
                "XWALK_MULTIPLEAPK": "true"
            },
            "cordova-plugin-device": {},
            "cordova-plugin-inappbrowser": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "cordova-plugin-wkwebview-engine": {},
            "ionic-plugin-keyboard": {},
            "cordova-plugin-app-version": {}
        }
    }
}

npm outdated:

C:\git\mobile>npm outdated
Package                             Current  Wanted  Latest
@ionic-native/core                   3.10.2  3.10.2   4.1.0
@ionic-native/in-app-browser         3.10.2  3.10.2   4.1.0
@ionic-native/splash-screen          3.10.2  3.10.2   4.1.0
@ionic-native/status-bar             3.10.2  3.10.2   4.1.0
@types/pouchdb                       5.4.28  5.4.28   6.3.0
@types/pouchdb-browser                5.4.4   5.4.4   6.1.1
@types/pouchdb-core                   5.4.5   5.4.5   6.1.5
cordova-plugin-console                1.0.5   1.0.5   1.0.7
cordova-plugin-crosswalk-webview      2.2.0   2.2.0   2.3.0
cordova-plugin-device                 1.1.4   1.1.4   1.1.6
cordova-plugin-inappbrowser           1.4.0   1.4.0   1.7.1
cordova-plugin-statusbar              2.2.1   2.2.1   2.2.3
cordova-plugin-whitelist              1.3.1   1.3.1   1.3.2
cordova-plugin-wkwebview-engine   1.1.4-dev     git     git
html-loader                           0.4.5   0.4.5   0.5.1
pouchdb                               5.4.5   5.4.5   6.3.4
sw-toolbox                            3.4.0   3.4.0   3.6.0
zone.js                              0.8.11  0.8.11  0.8.16

Copied from original issue: ionic-team/ionic#12628

imhoffd commented 7 years ago

Is the problem here? https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/core/plugin.ts#L240-L255

lostdev commented 7 years ago

Yep, but the param and return type jsdoc comments have been removed now. This would build fine for me. Ultimately I think the issue is with the jsdoc parser and not an issue with ionic.

If you need any additional information just let me know.

All the best, Carl

On Thu, Aug 10, 2017, 6:19 PM dwieeb notifications@github.com wrote:

Is the problem here? https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/core/plugin.ts#L240-L255

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2628#issuecomment-321688929, or mute the thread https://github.com/notifications/unsubscribe-auth/ABssur3QOs__6xCl3flsxsZTw4HrajTFks5sW4HygaJpZM4OzuqB .

dmitrydudkin commented 7 years ago

@lostdev, thanks! Changing jsDoc:

from
* @returns {function(...[any]): (undefined|*|Observable|*|*)}
to
* @returns {function([any]): (undefined|*|Observable|*|*)}

solved the problem

lostdev commented 7 years ago

@dwieeb why did you close this issue?

imhoffd commented 7 years ago

@lostdev You said it was an issue with the JSDoc parser, right? Is there something actionable I can do to fix this?

lostdev commented 7 years ago

Considering other people also have this issue, I think it would be a good idea investigate what the root cause of this is and make sure there is a proper fix moving forward.

My "fix" above is only a workaround and will not work in an environment that cannot be controlled (my fix is to edit the source of your node module). Refreshing my node packages will remove my "fix".

Just my thoughts!

imhoffd commented 7 years ago

I'll keep it open, but so far it looks like only a couple of people get this issue. I think it might be better as an issue of Ionic Native? https://github.com/ionic-team/ionic-native

RoyeA commented 7 years ago

Had the same issue. The root cause (for me) was due to changes in ionic-native. long time ago ( few months ) when I started on my current project, the ionic-native created a directory under node_modules. But with the new ( I guess ) changes, this directory shouldn't be exists, only node_modules/@ionic-native/.

I removed the node_modules/ionic-native, reinstalled the @ionic-native/core (and the rest of the native I'm using ) and the issue was resolved.

Batur24 commented 6 years ago

still has the same issue, don't have too much info to know what is really being wrong, so annoying!

imhoffd commented 6 years ago

@Batur24 Did you try @RoyeA's suggestion? Upgrading from ionic-native to the new @ionic-native/<package> packages seems to resolve the issue.