本文介绍了全局未在 ../node_modules/socket.io-parser/is-buffer.js 中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预先感谢您帮助我.我正在尝试在我的一个角度组件中连接套接字,但在浏览器的控制台中它抛出一个错误,指出全局未在 Object ../node_modules/socket.io-parser/is-buffer.js

这是我的 home.component.ts

import { Component, OnInit } from '@angular/core';import * as $ from 'jquery';import * as io from 'socket.io-client';@成分({选择器:'app-home',templateUrl: './home.component.html',styleUrls: ['./home.component.css']})导出类 HomeComponent 实现 OnInit {构造函数(){}ngOnInit() {}}var socket = io();

如果我取出socket.io-client和socket = io();该网站很好,但是当我包含它时,它崩溃了.

这是我的 package.json 文件

 "依赖项": {"@angular/animations": "^6.0.0","@angular/common": "^6.0.0","@angular/compiler": "^6.0.0","@angular/core": "^6.0.0","@angular/forms": "^6.0.0","@angular/http": "^6.0.0","@angular/platform-b​​rowser": "^6.0.0","@angular/platform-b​​rowser-dynamic": "^6.0.0","@angular/router": "^6.0.0","@types/jquery": "^3.3.1","@types/socket.io": "^1.4.33","body-parser": "^1.18.3","引导程序": "^4.1.1","core-js": "^2.5.4","快递": "^4.16.3","jquery": "^3.3.1","时刻": "^2.22.1","mongodb": "^3.1.0-beta4","ng4-twitter-timeline": "^1.0.8","popper.js": "^1.14.3","rxjs": "^6.0.0","socket.io": "^2.1.0","socket.io-client": "^2.1.0",zone.js":^0.8.26"}

我第一次尝试只使用 'socket.io' 没有用.然后我开始研究类似的问题.我什么也没找到.

我的最终目标是使用套接字从表单中获取数据并存储在数据库中.任何帮助将不胜感激.

更新(可能的解决方案):05/17/2018你必须使用:

(window as any) = window

在 polyfill.ts 中,这为我解决了问题.

更新(可能的解决方案 #2):05/29/2018

(window as any).global = window
解决方案
(window as any).global = window

如注释中所述,将上述代码添加到 polyfills.ts 文件中.

thanks in advance for helping me out. I'm trying to connect socket in one of my angular components, but in the console of the browser it throws an error saying that global is not defined at Object ../node_modules/socket.io-parser/is-buffer.js

This is my home.component.ts

import { Component, OnInit } from '@angular/core';
import * as $ from 'jquery';
import * as io from 'socket.io-client';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}


var socket = io();

If I take out the socket.io-client and socket = io(); the website is fine but when I include it, it crashes.

This is my package.json file

  "dependencies": {
    "@angular/animations": "^6.0.0",
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/http": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "@types/jquery": "^3.3.1",
    "@types/socket.io": "^1.4.33",
    "body-parser": "^1.18.3",
    "bootstrap": "^4.1.1",
    "core-js": "^2.5.4",
    "express": "^4.16.3",
    "jquery": "^3.3.1",
    "moment": "^2.22.1",
    "mongodb": "^3.1.0-beta4",
    "ng4-twitter-timeline": "^1.0.8",
    "popper.js": "^1.14.3",
    "rxjs": "^6.0.0",
    "socket.io": "^2.1.0",
    "socket.io-client": "^2.1.0",
    "zone.js": "^0.8.26"
  }

I first tried with just 'socket.io' which didn't work. I then started researching for a similar problem. I found nothing.

My end goal is to use socket to take data from forms and store in a database. Any help would be much appreciated.

UPDATE (POSSIBLE SOLUTION): 05/17/2018You have to use:

(window as any) = window 

in polyfill.ts, this resolved the problem for me.

UPDATE (POSSIBLE SOLUTION #2): 05/29/2018

(window as any).global = window
解决方案
(window as any).global = window

As already mentioned in comment, add the above code in the polyfills.ts file.

这篇关于全局未在 ../node_modules/socket.io-parser/is-buffer.js 中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 04:15