jquery__WEBPACK_IMPORTED_MODULE_4__.hubConnection 不是函数 [英] jquery__WEBPACK_IMPORTED_MODULE_4__.hubConnection is not a function
问题描述
我正在尝试让单一的(非 ASP.Core 的)使用 angular 8
如果我只是像这样向 index.html 添加信号器一个 jquery
<script src="https://code.jquery.com/jquery-3.4.1.min.js"integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="crossorigin="anonymous"></脚本><script src="https://cdn.jsdelivr.net/npm/signalr@2.4.1/jquery.signalR.min.js"></script>
一切正常.然而,我宁愿它像其他所有东西一样与 webpack 打包在一起,所以我去了我的 package.json 并安装了 signalr
"signalr": "2.4.1"
(我在 npm 中仔细检查过是否安装了 jquery 信号包依赖)
然后将 import * as $ from 'jquery';
添加到我进行信号通信的服务中.突然间我收到错误
jquery__WEBPACK_IMPORTED_MODULE_4__.hubConnection 不是函数
把这个放到signalr被初始化的地方
声明 var $: any;
然后进入
angular.json ->项目->建筑师 ->构建->选项
"scripts": [ "./node_modules/jquery/dist/jquery.min.js", "./node_modules/signalr/jquery.signalR.min.js" ],
>
I am trying to get singlar (non ASP.Core one) to work with angular 8
If I just add the signalr an jquery to index.html like so
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src=" https://cdn.jsdelivr.net/npm/signalr@2.4.1/jquery.signalR.min.js"></script>
everything works fine. I would however rather it worked packaged with webpack like everything else so I went to my package.json and installed signalr
"signalr": "2.4.1"
(I double checked in npm did install jquery signalr package depends on)
Then added import * as $ from 'jquery';
to the service where I do signalr communication. All of the sudden I get the error
jquery__WEBPACK_IMPORTED_MODULE_4__.hubConnection is not a function
put this into where signalr is being initialized
declare var $: any;
and then this into
angular.json -> projects -> architect -> build -> options
"scripts": [ "./node_modules/jquery/dist/jquery.min.js", "./node_modules/signalr/jquery.signalR.min.js" ],
这篇关于jquery__WEBPACK_IMPORTED_MODULE_4__.hubConnection 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!