Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
Webpack encore build error with computed name variable in stimulus controller

I was in webpack Version 5.40.0

In one of my script, i use computed variable name to make promise with async/await /import.. in a stimulus controller

It was working fine. Today when i update my dependency and add webpack to last version : 5.52.1, the build fail with an error on the first [ in this line : this.['module' + datagridshortName[i]]

'Syntax Error: Unexpected token' on the bracket.

So how to use computed name variable in webpack encore now ??

I just got back to webpack 5.40 and the code work.

Thanks for your explanations / help :)

My code :

    async createDatagridSource(){
   
    let datagridScName = [];
    let datagridshortName = [];
    Object.entries(this.datagrid).forEach(entry => {
        const [key, value] = entry;
        datagridScName.push(value.controllerNameSc);
        datagridshortName.push(value.shortName);
    });

    for (let i = 0; i < datagridshortName.length; i++) {
        this.['module' + datagridshortName[i]] = await import('../js/datagrid_config/' + datagridScName[i] + '_config');
        this.module=this.['module' + datagridshortName[i]];
        this.datafields=this.module.datafields();

        this.columns=this.module.columns();
        this.columngroups=this.module.columngroups();
        this.config=this.module.config();

        //source des données initiales
        this.['source' + datagridshortName[i]] ={
            datafields:this.datafields,
            data: { "viewArchives" : this.viewArchives,...this.sourceOtherdata(datagridshortName[i])},
            url: this.datagrid[datagridshortName[i]].urlInit,

            //********************************
            id: 'data',
            type: "POST",
            datatype: "json",
            root: 'data',
        }
        //adaptater de la source
        this.['dataAdapter' + datagridshortName[i]] = new $.jqx.dataAdapter(this.['source' + datagridshortName[i]]);
    }

    //renvoi l'identifiant du premier datagrid
    return datagridshortName[0];
}

Package.json

"devDependencies": {
"@symfony/webpack-encore": "^1.5.0",
"autoprefixer": "^10.2.6",
"core-js": "^3.15.1",
"file-loader": "^6.2.0",
"postcss": "^8.3.5",
"postcss-loader": "^5.3.0",
"precss": "^4.0.0",
"regenerator-runtime": "^0.13.7",
"sass": "^1.35.1",
"sass-loader": " ^12.1.0",
"webpack": "5.52.1",
"webpack-notifier": "^1.13.0"

},

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So it was just a typo mistake :

this.['module' + datagridshortName[i]] => this['module' + datagridshortName[i]]

Just remove the . and it's ok.

Explanation (thanks Lyzard kyng)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda