我们正在使用Angular 5.2.0,最近我们为WS功能添加了StompJS 2.2.3。
"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测试将不会加载错误:
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文件中。
感谢您的帮助。
答案 0 :(得分:0)
请使用https://github.com/stomp-js/stompjs中stompjs
的维护版本(npm @ stomp / stompjs)。 Angular https://github.com/stomp-js/ng2-stompjs也有一个专门的版本(npm @ stomp / ng2-stompjs)。
它们与Webpack,Rollup,RxJS和其他更新的库/工具链一起很好地工作。
这些已用TypeScript重写,并且所有这些都随类型库一起分发。这些随附指南和示例(请参阅:https://stomp-js.github.io/)。