【问题标题】:Webpack encore build error with computed name variable in stimulus controllerWebpack encore 在刺激控制器中使用计算的名称变量构建错误
【发布时间】:2021-11-09 20:38:53
【问题描述】:

我在 webpack 版本 5.40.0

在我的一个脚本中,我使用计算变量名在激励控制器中使用 async/await /import.. 做出承诺

工作正常。 今天,当我更新我的依赖项并将 webpack 添加到最后一个版本时:5.52.1,构建失败并在第一行出现错误 [ 在这一行中:this.['module' + datagridshortName[i]]

括号中的“语法错误:意外标记”。

那么现在如何在 webpack encore 中使用计算名称变量呢??

我刚回到 webpack 5.40 并且代码工作正常。

感谢您的解释/帮助:)

我的代码:

    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];
}

包.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"

},

【问题讨论】:

  • 我猜这个点根本就没有必要。 Explanation
  • @LyzardKyng 是的,你是真的!感谢您纠正这个错误^^

标签: javascript webpack webpack-encore stimulusjs


【解决方案1】:

所以这只是一个拼写错误:

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

只需删除 .没关系。

Explanation (感谢 Lyzard kyng)

【讨论】:

    猜你喜欢
    • 2021-12-25
    • 2023-01-01
    • 2022-11-18
    • 2021-03-06
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 2021-02-13
    相关资源
    最近更新 更多