0

When try to create production build in angular 4 by using command:

ng build --prod

And

ng build --prod --aot=false

I am getting following error in console:

chunk {scripts} scripts.d0765ae1a4bba4717f75.bundle.js (scripts) 381 kB [initial] [rendered]
chunk {0} main.20075152b680cf048d04.bundle.js (main) 1.79 MB [initial] [rendered]
chunk {1} polyfills.24783bc638c31078c9bb.bundle.js (polyfills) 60 kB [initial] [rendered]
chunk {2} styles.510fc4debb3c7f60a7cb.bundle.css (styles) 240 kB [initial] [rendered]
chunk {3} vendor.03d0b614f00528c8edb5.bundle.js (vendor) 9.27 MB [initial] [rendered]
chunk {4} inline.31e1fb380eb7cf3d75b1.bundle.js (inline) 798 bytes [entry] [rendered]

ERROR in vendor.03d0b614f00528c8edb5.bundle.js from UglifyJs
undefined

dist folder is also not created. After doing some search, I came across a fix to change the target from 'es5' to 'es6' in tsconfig.json. After making this change build is created without any error in console. But when I run the index.html, I get following error in browser console:

     Uncaught TypeError: Cannot convert undefined or null to object
        at Function.getPrototypeOf (<anonymous>)
vendor.62bee233ca73b4fe95c7.bundle.js:1

I have tried different solutions but haven't able to solve this error, project package.json

{
  "name": "admin-panek",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "@asymmetrik/ngx-leaflet": "^2.5.3",
    "@asymmetrik/ngx-leaflet-draw": "^2.7.1",
    "angular-calendar": "^0.22.3",
    "angular2-json2csv": "^1.1.2",
    "bootstrap": "^3.3.7",
    "chart.js": "^2.7.2",
    "core-js": "^2.4.1",
    "file-saver": "^1.3.3",
    "html2canvas": "^1.0.0-alpha.9",
    "html2pdf.js": "^0.8.2",
    "jquery": "^3.2.1",
    "json2csv": "^4.0.0-alpha.0",
    "json2xls": "^0.1.2",
    "jspdf": "^1.3.5",
    "leaflet": "^1.2.0",
    "leaflet-draw": "^1.0.2",
    "ng-lightning": "^2.0.1",
    "ng-socket-io": "^0.2.4",
    "ng2-charts": "^1.6.0",
    "ng2-cloudinary": "^0.9.2",
    "ng2-file-upload": "^1.3.0",
    "ng2-notify-popup": "^0.1.25",
    "ng2-select": "^2.0.0",
    "ngx-bootstrap": "^2.0.3",
    "ngx-filter-pipe": "^1.0.1",
    "ngx-order-pipe": "^1.1.1",
    "ngx-pagination": "^3.1.1",
    "ngx-permissions": "^3.2.3",
    "number-to-words": "^1.2.4",
    "pdfmake": "^0.1.35",
    "rxjs": "^5.4.2",
    "typescript": "^2.3.4",
    "xlsx": "^0.12.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "^1.7.0-rc.0",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.17",
    "@types/leaflet": "^1.2.6",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.8.2"
  }
}

Thanks in advance for helping me out to solve this problem.

  • If you change the "build" line to "build": "ng build --prod --no-aot" do you get the same error? – rrd Oct 10 '18 at 12:21
  • Possible duplicate of [AngularCli: disable minification](https://stackoverflow.com/questions/43557090/angularcli-disable-minification) – Reactgular Oct 10 '18 at 12:49
  • Most likely a bad vendor library. You can disable minification or you can remove the vendor library. I don't think there is anything Angular can do to fix a problem with UglifyJs. You should add dependencies slowly and carefully, and make sure they are well maintained and upto date. – Reactgular Oct 10 '18 at 12:53

1 Answers1

-2

Can you please check your polyfills.ts file and the below import statements are not commented.

/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';