If I run my app using ng serve, everything works as expected, and no errors are thrown. If I run the same code using ng serve -prod (even when using the same backend server), every call to my Rest service fails with
main.30347c9fa4d6d318dcf3.bundle.js:1 ERROR TypeError: Assignment to constant variable.
at s (main.30347c9fa4d6d318dcf3.bundle.js:1)
at XMLHttpRequest.l (main.30347c9fa4d6d318dcf3.bundle.js:1)
at e.invokeTask (polyfills.ee89d2044fe261e27311.bundle.js:1)
at Object.onInvokeTask (main.30347c9fa4d6d318dcf3.bundle.js:1)
at e.invokeTask (polyfills.ee89d2044fe261e27311.bundle.js:1)
at t.runTask (polyfills.ee89d2044fe261e27311.bundle.js:1)
at t.invokeTask [as invoke] (polyfills.ee89d2044fe261e27311.bundle.js:1)
at _ (polyfills.ee89d2044fe261e27311.bundle.js:1)
at XMLHttpRequest.k (polyfills.ee89d2044fe261e27311.bundle.js:1)
I can build the app without -prod, and deploy it, and it works too. I think this is related to uglify-es or WebPack, but I'm not entirely sure. Here are my package.json dependencies. Any ideas?
dependencies:
"@angular/animations": "^5.2.4",
"@angular/cdk": "^5.1.1",
"@angular/common": "^5.2.4",
"@angular/compiler": "^5.2.4",
"@angular/core": "^5.2.4",
"@angular/forms": "^5.2.4",
"@angular/http": "^5.2.4",
"@angular/material": "^5.1.1",
"@angular/platform-browser": "^5.2.4",
"@angular/platform-browser-dynamic": "^5.2.4",
"@angular/router": "^5.2.4",
"bootstrap": "4.0.0",
"commonjs": "0.0.1",
"copyfiles": "^1.2.0",
"crypto-js": "^3.1.9-1",
"hammerjs": "^2.0.8",
"material-design-icons": "^3.0.1",
"postcss-merge-rules": "^2.1.2",
"requirejs": "^2.3.5",
"rxjs": "^5.5.6",
"zone.js": "^0.8.20"
devDependencies:
"@angular/cli": "^1.6.8",
"@angular/compiler-cli": "^5.2.4",
"@angular/language-service": "^5.2.4",
"@types/jasmine": "^2.8.6",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^8.5.9",
"angular-ide": "^0.9.39",
"codelyzer": "^4.1.0",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.4.1",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.2.4",
"ts-node": "~3.3.0",
"tslint": "~5.8.0",
"typescript": "2.6.2",
"webpack-concat-plugin": "^2.4.2"
This is my code to call my rest service, it never makes it back.
/// get data with request parameters
/// (e.g.) serverRoot/Parts?uidPart=52640-aof098-f9f-f8f-fff-990987
getData_With_Request_Parameters(ep: EndPoints, params: Map<string, string>) {
console.log('Creating Path');
let path: string = this.serverRoot + '/' + this.getEndPoint(ep) + '?';
console.log('creating param map');
// append all of the parameters to the url
for (const key of params.keys()) {
path += key + '=' + params.get(key) + '&';
}
console.log('altering the path');
// remove the last '&'
path = path.slice(0, path.length - 1);
console.log('sending get to path');
return this.http.get(path).map((res: Response) => res);
}
This is my callback, that never gets executed
this.restService.getData_With_Request_Parameters(EndPoints.AuthenticateUser, data).subscribe(res => {
console.log('INSIDE REST CALLBACK ' + email);
if (res && res.toString() === 'true') {
this.authenticated = true;
this.accessCode = hashCode;
this.loginError = '';
} else {
this.loginError = 'Login Failed.';
this.authenticated = false;
this.accessCode = '';
}
this.isLoggingIn = false;
console.log(res);
}, err => {this.isLoggingIn = false; console.log(err); this.loginError = 'Network Error. The server may be inaccessible.'; }
);
Here is my ng -v
Angular CLI: 1.6.8
Node: 8.9.4
OS: win32 x64
Angular: 5.2.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.1.1
@angular/cli: 1.6.8
@angular/material: 5.1.1
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.6.2
webpack-concat-plugin: 2.4.2
webpack-uglify-js-plugin: 1.1.9
webpack: 3.10.0
const. You can try using the Pretty Print feature in DevTools and then clicking on the frame in the stack trace to find the exact place that the error occurs. The code will still be minified unless you generate and enable sourcemaps, but it may be decipherable.