Uglify failed on prod build

Running app-scripts build: --prod --address 0.0.0.0 --port 8100 --p 8100 --livereload-port 35729 --r 35729 --iscordovaserve --externalIpRequired --nobrowser

[11:54:21]  build prod started ...
[11:54:21]  clean started ...
[11:54:21]  clean finished in 96 ms
[11:54:21]  copy started ...
[11:54:21]  ngc started ...
[11:54:36]  ngc finished in 15.72 s
[11:54:36]  preprocess started ...
[11:54:36]  deeplinks started ...
[11:54:37]  deeplinks finished in 673 ms
[11:54:37]  optimization started ...
[11:54:38]  copy finished in 17.34 s
[11:54:54]  optimization finished in 16.93 s
[11:54:54]  preprocess finished in 17.60 s
[11:54:54]  webpack started ...
[11:56:30]  webpack finished in 95.61 s
[11:56:30]  sass started ...
[11:56:30]  uglifyjs started ...
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova).
Error: Uglify failed: Unexpected token: name (AboutPage) in undefined at line undefined, col undefined, pos undefined
Segmentation fault: 11

I’ve looked at my usage of AboutPage - there’s nothing special, it only occurs 4 times in the entire codebase and the syntax is fine. I think that’s a red herring. How do I debug this? The dev build works fine.

Ionic Info

cli packages:

@ionic/cli-utils  : 1.6.0 (/path/to/myapp/node_modules/ionic/node_modules/@ionic/cli-utils)
ionic (Ionic CLI) : 3.6.0 (/path/to/myapp/node_modules/ionic)

global packages:

Cordova CLI : 7.0.1

local packages:

@ionic/app-scripts              : 2.0.2
@ionic/cli-plugin-cordova       : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms               : android 6.2.3 ios 4.4.0
Ionic Framework                 : ionic-angular 3.5.3

System:

Android SDK Tools : 26.0.2
Node              : v6.9.1
OS                : macOS Sierra
Xcode             : Xcode 8.3.3 Build version 8E3004b
ios-deploy        : 1.9.1
npm               : 3.10.8

Update this first.

Then run command again with --verbose.

I’ve updated app-scripts, it is now at 2.1.4

ionic cordova build --release android --prod --verbose
[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: '/Users/mbeckett/sites/apps/meded-build-test', local: true, binPath:
        '/Users/mbeckett/.nvm/versions/node/v6.9.1/lib/node_modules/ionic/bin/ionic', libPath:
        '/Users/mbeckett/sites/apps/meded-build-test/node_modules/ionic/dist/index.js' }
[DEBUG] Loading local plugin @ionic/cli-plugin-proxy
[DEBUG] Throwing PLUGIN_NOT_INSTALLED for local @ionic/cli-plugin-proxy
[DEBUG] Loading local plugin @ionic/cli-plugin-cordova
[DEBUG] Loading local plugin @ionic/cli-plugin-ionic-angular
Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

[13:02:48]  build prod started ...
[13:02:48]  clean started ...
[13:02:48]  clean finished in 3 ms
[13:02:48]  copy started ...
[13:02:48]  ngc started ...
[13:02:58]  ngc finished in 9.66 s
[13:02:58]  preprocess started ...
[13:02:58]  deeplinks started ...
[13:02:59]  deeplinks finished in 815 ms
[13:02:59]  optimization started ...
[13:02:59]  copy finished in 10.71 s
[13:03:12]  optimization finished in 13.33 s
[13:03:12]  preprocess finished in 14.14 s
[13:03:12]  webpack started ...
[13:04:37]  webpack finished in 85.08 s
[13:04:37]  sass started ...
[13:04:37]  uglifyjs started ...
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova).
Error: Uglify failed: Unexpected token: name (AboutPage) in undefined at line undefined, col undefined, pos undefined
[DEBUG] Error: Uglify failed: Unexpected token: name (AboutPage) in undefined at line undefined, col undefined, pos
        undefined
        at BuildError.Error (native)
        at new BuildError
        (/Users/mbeckett/sites/apps/meded-build-test/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
        at taskReject
        (/Users/mbeckett/sites/apps/meded-build-test/node_modules/@ionic/app-scripts/dist/worker-process.js:36:22)
        at /Users/mbeckett/sites/apps/meded-build-test/node_modules/@ionic/app-scripts/dist/worker-process.js:14:13
Segmentation fault: 11

Can we see them? It sure does seem awfully specific and consistent for a red herring.

1 Like

The page itself

@Component({
  selector: 'page-about',
  templateUrl: 'about.html',
})
export class AboutPage {
  public appversion: string = 'N/A';

Imported into my pages constant

import { AboutPage } from '../pages/about/about';

export const MED_PAGES = [
    AboutPage,

Imported in my app.component.ts

import { AboutPage } from '../pages/about/about';

In my navigation array in app.component.ts

loggedOutPages: Array<{title: string, component: any}> = [
        { title: 'menus.main.validate', component: ValidateDevicePage },
        { title: 'menus.main.registerDevice', component: RegisterDevicePage },
        { title: 'menus.main.contact', component: ContactPage },
        { title: 'menus.main.about', component: AboutPage },
        { title: 'menus.main.settings', component: SettingsPage }
  ];

It’s no different than any other page in this app, and it’s no different than any pages in any of the other apps I’ve done that have compiled correctly.

This one looks most suspicious to me.

Not sure what’s suspicious about it, it’s the same pattern I’ve used many times. I did a prod build of my big app a week ago that uses it.

I’m just building an array of pages to import in to the app module - I have 21 pages, so it reduces the size of my app.module by 20 imports, 20 declarations, and 20 entry component entries by including them in an array.

However, on your suspicion I have removed that pattern, rewrote the app.module.ts with all the explicit imports/etc and still getting the same issue.

1 Like

Can you please post your tsconfig.json and TypeScript version?

tsconfig.json

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

Typescript: 2.3.4

Try changing this to “es5”.

Yeah @rapropos - that was it, and it’s es5 in my other projects too. Not sure why it was es6 here. I’m past the uglify stage. Thanks a bunch!

webpack #2972 put me on that trail, if you’re curious.

1 Like