您可能需要一个合适的加载器来处理这种文件类型,目前没有配置加载器来处理这种文件。 C#

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. C#

我正在尝试使用 javascript 中的 $.getJSON() 函数,但出现此错误:

"You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."

这是我的 javascript:

$(document).ready(function () {
    console.log("Hello from riskanalysis.delete.js");

    var categoryTd = $('#categoryId');
    var categoryText = categoryTd.text();
    var categoryInt = parseInt(categoryText);
    console.log(categoryInt);
    console.log(categoryText);

        // Send an AJAX request
    $.getJSON("/riskanalysis/getCategoryNameById?id=" + categoryInt)
    console.log("Hello before");
            .done(function (categoryName) {
                // On success
                console.log("Category name is: " + categoryName);
                categoryTd.text(categoryName); 
            });

    console.log("Hello after");
});

这是我的 webpack.config.js 文件:

module.exports = {
    entry:
    {
        shared: './src/shared.js',
        home: './src/home/home.js',
        riskanalysisSearch: './src/riskanalysis/riskanalysis.search.js',
        riskanalysisCreate: './src/riskanalysis/riskanalysis.create.js',
        riskanalysisDelete: './src/riskanalysis/riskanalysis.delete.js',
        dropdown: './src/dropdown/dropdown.js',
        actionplan: './src/actionplan/actionplan.js'
    },
    output: {
        filename: '../wwwroot/js/[name].js'
    },
    optimization: {
        splitChunks: {
            cacheGroups: {
                vendor: {
                    test: /[\/]node_modules[\/](jquery)[\/]/,
                    name: 'vendor',
                    chunks: 'all'
                }
            }
        }
    }

};

这是错误:

奇怪的是,在我的所有其他 javascript 文件中,它都运行良好。

有谁知道哪里出了问题?已经谢谢了!

错误的原因是行 console.log("Hello before");,将此行移到 $.getJSON("/riskanalysis/getCategoryNameById?id=" + categoryInt) 上方,使其看起来像这样:

console.log("Hello before");
$.getJSON("/riskanalysis/getCategoryNameById?id=" + categoryInt)
        .done(function (categoryName) {
            // On success
            console.log("Category name is: " + categoryName);
            categoryTd.text(categoryName); 
        });

console.log("Hello after");

显示此错误的行是:Module parse failed: Unexpected token (13:12)

关于错误 You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. 这是因为此文件的完整文件扩展名是 .delete.js 这使得 webpack 认为这不是一个正常的 .js 文件。 Webpack 将尝试为 .delete.js 个文件找到一个文件加载器,因为不存在它将回退到 .js 个文件加载器。由于上述错误,js 解析器将失败导致此错误。