在此先感谢帮助我.我正在尝试在我的一个角度组件中连接套接字,但是在浏览器的控制台中它会抛出一个错误,说明没有在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';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
var socket = io();
Run Code Online (Sandbox Code Playgroud)
如果我拿出socket.io-client和socket = io(); 网站很好但是当我把它包括在内时,它会崩溃.
这是我的package.json文件
"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": …
Run Code Online (Sandbox Code Playgroud) 感谢您花时间阅读我的问题。当我运行 ng serve 时,我的网站运行良好。当我运行 ng build --prod 时,它也能正常工作。问题是,当我尝试在 dist 中呈现 index.html 时,我收到 404 错误。错误是我的主文件、样式文件和 polyfill 文件的 404 错误。我正在尝试建立一个后端,以便我可以处理卡付款。任何帮助将不胜感激 - 已经把我的头撞在墙上几个小时了,没有下定决心。这是我的代码如下:
服务器.js
var express = require('express');
var app = express();
var server = require('http').Server(app);
var bodyParser = require('body-parser');
app.use(express.static(__dirname));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
server.listen(2000, function(){
console.log('Listening on 2000..')
});
console.log(__dirname);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/dist/culture/index.html');
});
Run Code Online (Sandbox Code Playgroud)
源代码/索引.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Culture</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" …
Run Code Online (Sandbox Code Playgroud)