Javascript bundle.js中未定义jQuery

Javascript bundle.js中未定义jQuery,javascript,jquery,node.js,webpack,hugo,Javascript,Jquery,Node.js,Webpack,Hugo,我已经被困在这个问题上好几天了,我已经尝试了几十种不同的修复方法。首先,我使用Hugo、Webpack、Node.js和Babel。目前,所有内容至少都在编译中,但当我查看localhost控制台时,我看到以下错误: Uncaught ReferenceError: jQuery is not defined at Object.609 (bundle.js:2) at n (bundle.js:2) at Object.83 (bundle.js:2) at n

我已经被困在这个问题上好几天了,我已经尝试了几十种不同的修复方法。首先,我使用Hugo、Webpack、Node.js和Babel。目前,所有内容至少都在编译中,但当我查看localhost控制台时,我看到以下错误:

Uncaught ReferenceError: jQuery is not defined
    at Object.609 (bundle.js:2)
    at n (bundle.js:2)
    at Object.83 (bundle.js:2)
    at n (bundle.js:2)
    at Module.150 (bundle.js:2)
    at n (bundle.js:2)
    at bundle.js:2
    at bundle.js:2
609 @ bundle.js:2
n @ bundle.js:2
83 @ bundle.js:2
n @ bundle.js:2
150 @ bundle.js:2
n @ bundle.js:2
(anonymous) @ bundle.js:2
(anonymous) @ bundle.js:2
localhost/:1 Refused to apply style from 'http://localhost:1313/scss/node_modules/bootstrap-icons/font/bootstrap-icons.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
localhost/:1 Refused to apply style from 'http://localhost:1313/node_modules/animate.css/source/animate.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
localhost/:1 Refused to apply style from 'http://localhost:1313/home/elijah/GolandProjects/ReplayRLB/website/testsite1/assets/plugins/magnific-popup/magnific-popup.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
现在我写这篇文章的主要理由是解决jQuery问题,但对另一个问题的深入了解也会很好,因为我也在这方面停留了一段时间

webpack.config.js
const path=require('path');
const webpack=require('webpack');
//const WebpackManifestPlugin=require('webpack-manifest-plugin');
module.exports={
模块:{
规则:[
{
测试:/\.js$/,,
排除:/node_模块/,
用法:['babel-loader'],
}
]
},
条目:'./assets/js/script.js',
输出:{
path:path.resolve(uu dirname,'assets','js'),
文件名:“bundle.js”,
},
外部:{
jquery:'jquery',
},
/*插件:[
新的webpack.ProvidePlugin({
$:“jquery”,
jQuery:'jQuery'
})
]*/
};
我从script.js(又名主js文件)导入的内容:

app.use(“/static”,express.static('./static/');
从“./plugins/jquery/jquery.min.js”导入$;
从“./plugins/jQuery/jQuery.min.js”导入jQuery;
导入“./plugins/@popperjs/core/lib/popper.js”;
导入“./plugins/googlemap/map.js”;
导入“./plugins/magnific popup/jquery.magnific popup.min”;
从“./plugins/Shuffle/Shuffle.min.js”导入Shuffle;
导入“./plugins/slick/slick.min.js”;
从“lozad”中导入lozad;
//定价脚本
导入“./js/pricing/boosting.js”;
导入“./js/pricing/tourneyTitle.js”;
导入“./js/pricing/placements.js”;
导入“./js/pricing/coaching.js”;
/* ========================================================================= */
/*jQuery加载初始化
/* ========================================================================= */
window.$=require('../plugins/jquery/jquery.min');
window.jQuery=$;
需要('./script.js');
/* ========================================================================= */
/*随机加载初始化
/* ========================================================================= */
const shuffleInstance=new Shuffle(document.getElementById('grid'){
itemSelector:“.js项”,
sizer:'.js shuffle sizer',
});
/* ========================================================================= */
/*延迟加载初始化
/* ========================================================================= */
const observer=lozad();//惰性加载元素,默认选择器为“.lozad”
观察者观察();
为我的主要js源调用bundle


请注意,这不是在静态/资产中,因为当我尝试它不起作用时,它给了我一个错误,说你不能将静态文件发送到客户端或web(类似于这些内容)。我认为我的资产目录相当于src目录。

错误“jquerynotdefined”通常意味着您没有加载jQuery库。 我想你是在尝试使用ES6导入语法吧

  • 从“jQuery”导入{$,jQuery}类型语句取决于您使用的jQuery版本,请检查(我不能告诉您使用的是哪个版本的jQuery),而且jQuery导入似乎有点不同?参见上面的导入语句
  • 为了保持简单,您还可以测试传统的jQuery导入语句la:
    并查看是否可以在控制台中使用基本jQuery语句
  • 很抱歉,我的英语不是最好的,但以上内容可能有助于调试


    一定要让我知道。

    我最终只是在head.html中使用了cdn,而且它很有效。现在,我有其他问题,我可能会张贴关于虽然。Like样式未在bundle.js中定义。我认为这与我在SCS中的导入有关,也可能是因为以下错误:拒绝应用“”中的样式,因为它的MIME类型(“text/plain”)不是受支持的样式表MIME类型,并且启用了严格的MIME检查。例如,我如何更改一个奇怪插件的MIME类型。如果您有新问题,我看看能不能帮上忙。我会小心的。祝你好运,是吗?我已经做到了!只要点击我的名字,你就会看到:)