问题描述
我们正在使用Angular 5.2.0,最近我们为WS功能添加了StompJS 2.2.3.
We are using Angular 5.2.0 and we recently added StompJS 2.2.3 for WS features.
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"...",
"stompjs": "^2.3.3",
},
但是,自添加以来,Karma测试将不会加载错误:
However, since the addition, Karma tests won't load with the error :
ERROR in ./node_modules/stompjs/lib/stomp-node.js
Module not found: Error: Can't resolve 'net' in 'C:\Workspace\Projets\HAW_WEB\common\hubanywhere-angular-common\node_modules\stompjs\lib'
@ ./node_modules/stompjs/lib/stomp-node.js 14:8-22
@ ./node_modules/stompjs/index.js
@ ./src/app/common/service/stomp/stomp.service.ts
@ ./src/app/common/service/stomp/stomp.service.spec.ts
@ ./src \.spec\.ts$
@ ./src/test.ts
似乎我们必须允许karma加载本地的"net"程序包,但是我找不到在karma.conf.js文件中放置的正确配置.
It seems we have to allow karma to load the native 'net' packages, but I can't find the correct configuration to place in the karma.conf.js file.
感谢您的帮助.
推荐答案
请使用stompjs的维护版本> https://github.com/stomp-js/stompjs (npm @ stomp/stompjs).还有一个专门用于Angular的版本 https://github.com/stomp-js/ng2- stompjs (npm @ stomp/ng2-stompjs).
Please use maintained version of stompjs
from https://github.com/stomp-js/stompjs (npm @stomp/stompjs). There is also a specialized version for Angular https://github.com/stomp-js/ng2-stompjs (npm @stomp/ng2-stompjs).
它们可以与Webpack,Rollup,RxJS和其他更新的库/工具链一起很好地工作.
These work well with Webpack, Rollup, RxJS and other newer libraries/tool-chain.
这些已在TypeScript中重写,并且所有这些都随类型库一起分发.这些带有指南和示例(请参阅: https://stomp-js.github.io/ ).
These have been re-written in TypeScript and all of these are distributed with type libraries. These come with guides and samples (see: https://stomp-js.github.io/).
这篇关于角度& StompJS引发业力测试负载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!