4

我正在使用npm install socket.io-streamsocket.io-stream在我的角度组件上实现,如下所示:

import * as io from 'socket.io-client';
import * as ss from 'socket.io-stream';

我只想像这样创建一个双工流:

stream=ss.createStream();

运行时出现此错误ng build

ERROR in ./node_modules/socket.io-stream/lib/iostream.js
Module not found: Error: Can't resolve 'stream' in ' 
'C:\Users\geoffroy\Documents\Mines Alès\2A\Stage\WebService based 
GUI\WebApp\node_modules\socket.io-stream\lib'
ERROR in ./node_modules/socket.io-stream/lib/blob-read-stream.js
Module not found: Error: Can't resolve 'stream' in 
'C:\Users\geoffroy\Documents\Mines Alès\2A\Stage\WebService based 
GUI\WebApp\node_modules\socket.io-stream\lib'

我不明白,因为在我的 server.js 上它似乎工作..

我尝试运行该命令npm install stream,但没有错误ng build。但是当我启动我的应用程序时,我的浏览器控制台中出现了一个新错误:

inherits_browser.js:5 Uncaught TypeError: Cannot read property 'prototype' of undefined
at Object.inherits (inherits_browser.js:5)
at Object../node_modules/socket.io-stream/lib/iostream.js (iostream.js:10)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/socket.io-stream/lib/socket.js (socket.js:4)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/socket.io-stream/lib/index.js (index.js:1)
at __webpack_require__ (bootstrap:76)
at Object../node_modules/socket.io-stream/index.js (index.js:2)
at __webpack_require__ (bootstrap:76)

谢谢你的帮助

4

1 回答 1

0

只需在 polyfills.ts 中添加这一行

// Add global to window, assigning the value of window itself. (window as any).global = window;

于 2018-08-31T06:00:21.560 回答