![](/img/trans.png)
[英]Loader Webpack "You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file."
[英]You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. C#
我正在尝试在 javascript 中使用$.getJSON()
function 但我收到此错误:
“您可能需要适当的加载程序来处理此文件类型,目前没有配置加载程序来处理此文件。”
这是我的 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解析器将失败导致此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.