Error: Unexpected token: name (Players) www/build/main.js at line 26325, col 4, pos 888867

Hi everyone! I tried to run “ionic cordova run android --prod” but I’ve got the following error in my terminal.

[19:33:28] uglifyjs started …
[WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova). Your plugins may be out of date.
Error: Unexpected token: name (Players) in /Volumes/Macintosh Data/IONIC_PROJECT/hukulele/www/build/main.js at line 26325, col 4, pos 888867

Here is my Players class :

import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

@Injectable()
export class Players{
    players: {name: string}[];
    
    addPlayer(player: {name: string}){
        this.players.push(player);
    }
    
    getPlayers(){
        return this.players.slice();
    }
    
    setPlayers(liste: {name: string}[]){
        this.players = liste;
    }
    
    initPlayers(){
        this.players = [{"name":""},{"name":""},{"name":""},{"name":""},{"name":""}];
    }
}

And the main.js file at line 26325 :

let Players = class Players {
    addPlayer(player) {
        this.players.push(player);
    }
    getPlayers() {
        return this.players.slice();
    }
    setPlayers(liste) {
        this.players = liste;
    }
    initPlayers() {
        this.players = [{ "name": "" }, { "name": "" }, { "name": "" }, { "name": "" }, { "name": "" }];
    }
};

Please help!

What happen without --prod?

Error: Unexpected token: name (Players) in /Volumes/Macintosh Data/IONIC_PROJECT/hukulele/www/build/main.js at line 26325, col 4, pos 888867

But when I run ionic serve or ionic cordova run android (without --prod option), it works perfectly. I think the problem happens when it try to minify but I don’t know why it won’t work with --prod?

Then I think it is time for “disable code with comments” debugging. Go through it until you found it, then tell us.

All the code is commented but error still there

Hi @Ny_Aina_RAKOTOBE,

I think this is related to your type declarations, for example:

export class Players{
    players: {name: string}[];

I’d write it like that

`` players: {name: string}[]};(it miss an ending })

Hi! It tell me > Declaration or statement expected

anwyays something it wrong with that, the "{ should be closed and fast. Then you code has other form issues. if it silentlry crash.

No it didn’t. It was fine before. You added a spurious }.

1 Like

Can you please tell us the filename containing this class?

@rapropos it does sorry, but the declaration still miss something :stuck_out_tongue:

By the way, for performance issues, you could use loops. Or define a value as boolean to start with something.

I’m having the same issue