0
votes

With Angular 2 (cli), When running ng build --prod, I get a very strange error, that makes me believe that isn't the error at all.

He says there is something wrong on line 5 of this file:

    import { Injectable } from '@angular/core';
    import * as io from "socket.io-client";

    @Injectable()
    export default class SocketService {

        socket;
        //
        // constructor() {}
        //
        init() {
        //     this.socket = io('localhost:3000');
        }
    }

It gives this error:

ERROR in main.b1e7bf5cf9ed04b8ff8d.bundle.js from UglifyJs
SyntaxError: Unexpected token: name (SocketService) 
[/Users/kewinbrandsma/Projects/TradeJS/~/angular2-template-loader!/Users/kewinbrandsma/Projects/TradeJS/src/client/app/services/socket.service.ts:5,0][main.b1e7bf5cf9ed04b8ff8d.bundle.js:3265,4

While running it with ng serve (dev mode) gives no errors at all and works perfectly. So its really something UglifyJS doesn't like..

The error stack shows a line number for the 'pre-compiled bundle.js'. (main.b1e7bf5cf9ed04b8ff8d.bundle.js:3265,4) but I can't seem to find the file, as it probably still only lives in memory.

Is it always destroyed after a unsuccessful build, or is there a way to write to disk even when uglify complains? Cause it makes it impossible to debug the Uglify Error


It seems to have something todo with https://github.com/angular/angular-cli/issues/1333

So for now, just to run 1 (none minified) build, I disable Uglify entirely in webpack-build-production.js.. But this file lives in the angular node_modules, so its not a solution at all.

1

1 Answers

0
votes

After digging through it a lot more, I found that settings tsconfig to target: "es5" solves it. The problem I was facing, is that typescript does not yet support async / await with es5.. So I could not use target: "es5"..

But installing typescript@rc as npm package worked! The new 2.1 version supports async / await in es5 mode.

This package will probably be released in the upcoming months.