問題描述:
Angular項目中使用了socketio-client
庫,
{
"dependencies": {
...
"@feathersjs/socketio-client": "^4.4.3",
...
},
}
使用:
import socketio from '@feathersjs/socketio-client'
@Injectable()
export class Socket {
public socket: SocketIOClient.Socket
public app: any
constructor() {
this.app = feathers()
.configure(socketio(this.socket, {timeout: 20000}))
.configure(authentication({path: '/login', storage: window.localStorage}))
}
}
運行後報錯
global is not defined at Object…/node_modules/socket.io-parser/is-buffer.js
說在Object ./node_modules/socket.io-parser/is-buffer.js中沒有定義全局變量
解決辦法:
在polyfills.ts
file中添加
// polyfills.ts
(window as any).global = window
參考:Global is not defined at …/node_modules/socket.io-parser/is-buffer.js