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


#1

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!


#4

What happen without --prod?


#5

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?


#6

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


#7

All the code is commented but error still there


#8

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 })


#9

Hi! It tell me > Declaration or statement expected


#10

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


#13

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


#14

Can you please tell us the filename containing this class?


#15

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


#16

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


#17

I’m having the same issue