Tyler
Tyler

Reputation: 678

ng build --prod UnhandledPromiseRejectionWarning: Unhandled promise rejection

Angular 4.3 I get the following error when trying to ng build --prod

94% asset optimization(node:7184) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token: name (i)

I have no idea where this issue stems from as thats the only error I can find.

Upvotes: 5

Views: 1926

Answers (4)

priya_21
priya_21

Reputation: 159

npm install @angular/[email protected] ( @maximedupre answer ) Also need to have one more step before installing the above command is to open vs code in administrator mode

Upvotes: 0

Darren Smith
Darren Smith

Reputation: 2488

I have similar issue for an Angular 5 project, when running ng build --prod for ng version 1.5.2

94% asset optimization(node:26226) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected token: name (Commented)

I've tracked the problem to the include of a particular script via the .angular-cli.json, I have this :

"scripts": [
    "../libs/autobahn-js-built-17.5.2/autobahn.js"
],

... and further, I suspect the error happens during the minification stage (when uglifyjs would be invoked).

I can't seem to find any way to get further logging / diagnostics from ng , (I tried --verbose but just gives mainly timing stats, rather information on what sub programs are being invoked etc) ... will continue digging, suspicion is incompatibility between uglifyjs and the external javascript.

Upvotes: 0

Philipp P
Philipp P

Reputation: 619

Same here :(

In my case the problem occurs in combination with popper.js as stated here: https://github.com/angular/angular-cli/issues/7725

EDIT: I found a solution: Instead of using this one in the Angular-CLI-Configuration (.angular-cli.json):

"scripts": [
  ...
  "../node_modules/popper.js/dist/popper.min.js",
  ...
],

I used that one (i changed the library to the /dist/umd one):

"scripts": [
 ...
 "../node_modules/popper.js/dist/umd/popper.min.js",
 ...
],

Upvotes: 2

Maxime Dupré
Maxime Dupré

Reputation: 5737

Revert the angular CLI version 1.3.2 until this bug gets fixed:

npm install @angular/[email protected] (add -g if you are using a global package)

You should be able to build now :).

Upvotes: 3

Related Questions