Angular 10 Global is not defined at ..node

    技术2022-07-11  95

    问题描述: 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

    Processed: 0.012, SQL: 12