Error: ./~/ionic-native/dist/esm/plugins/plugin.js Module build failed: TypeError: Cannot read property 'type' of undefined

Hi.

I had the same error as you, but for me it occurs during a ionic cordova build android --prod. It wasn’t related to any unused imports.

I’ll update if I find a fix, but here’s my ionic info if anyone has any ideas:

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

    @ionic/cli-plugin-cordova       : 1.6.1
    @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 : 1.3.7
    Cordova Platforms  : android 6.2.3 ios 4.3.1
    Ionic Framework    : ionic-angular 3.5.3

System:

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

The error:

[WARN] Error occurred during command execution from a CLI plugin
       (@ionic/cli-plugin-cordova).
Error: ./~/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)
 @ ./~/ionic-native/dist/esm/index.js 146:0-33
 @ ./src/providers/network-status.ts
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts

Do you have any leeway in changing your package versions? Try @ionic/app-scripts@2.1.3. If that doesn’t work, send us your package.json and webpack.config.js files.

Sorry for the late reply!

I could try to downgrade next week to see what happens. In the meantime, here are my configuration files:

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/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-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",
        "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": "1.3.7",
        "@ionic/cli-plugin-cordova": "1.6.1",
        "@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": {}
        }
    }
}

webpack.config.js

var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);

module.exports = {
  entry: process.env.IONIC_APP_ENTRY_POINT,
  output: {
    path: '{{BUILD}}',
    publicPath: 'build/',
    filename: process.env.IONIC_OUTPUT_JS_FILE_NAME,
    devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
  },
  devtool: process.env.IONIC_SOURCE_MAP_TYPE,

  resolve: {
    extensions: ['.ts', '.js', '.json'],
    modules: [path.resolve('node_modules')]
  },

  module: {
    loaders: [
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.ts$/,
        loader: process.env.IONIC_WEBPACK_LOADER
      },
      {
        test: /\.js$/,
        loader: process.env.IONIC_WEBPACK_TRANSPILE_LOADER
      }
    ]
  },

  plugins: [
    ionicWebpackFactory.getIonicEnvironmentPlugin(),
  ],

  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }
};

I think it’s an issue with Ionic Cloud. Are you using that? If so, remove all references and try again to see if the error disappears. You may want to upgrade your ionic app scripts as well.

Not using Ionic Cloud; I was pretty sure I had already updated the ionic-app-scripts but I’ll do that soon to see if it helps.

Thanks,
Carl

Okay so I updated my app-scripts to 2.1.3 and still have the same issue. I am not using any Ionic cloud references. Here’s the latest error (which is probably the same as in my first post):

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

Ionic info:


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

    @ionic/cli-plugin-cordova       : 1.6.1
    @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.5.3

System:

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

I downgraded the ionic-app-scripts to 1.3.1 and the error looks like this now (no stack trace):

[WARN] Error occurred during command execution from a CLI plugin
       (@ionic/cli-plugin-cordova).
TypeError: Cannot read property 'type' of undefined

I’m running out of things to try!

FYI: Seems to be related to https://github.com/angular/angular-cli/issues/7110

Still investigating…

Update: I can work around the issue by removing all method comments from the file: node_modules\ionic-native\dist\esm\plugins\plugin.js.

Seems like an update to angular-cli should fix the issue long-term, but I’m good for now.

Update: Issue logged at https://github.com/ionic-team/ionic/issues/12628

1 Like

Late But i found solution
in your network status provider you are imported ionic-native package only ,you should change it to @ionic-native/specific-module-name