Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Express 在Web包绑定的typescript中使用socket.io时出错_Express_Typescript_Socket.io_Webpack - Fatal编程技术网

Express 在Web包绑定的typescript中使用socket.io时出错

Express 在Web包绑定的typescript中使用socket.io时出错,express,typescript,socket.io,webpack,Express,Typescript,Socket.io,Webpack,我试图通过socket.io在带有expressjs的typescript编写的节点服务器中使用web套接字。与网页包捆绑 服务器代码如下所示: import * as Express from "express"; import * as SocketIO from "socket.io"; import * as Http from "http"; const app = Express(); app.get("/", (reqest: Express.Request, response

我试图通过socket.io在带有expressjs的typescript编写的节点服务器中使用web套接字。与网页包捆绑

服务器代码如下所示:

import * as Express from "express";
import * as SocketIO from "socket.io";
import * as Http from "http";

const app = Express();

app.get("/", (reqest: Express.Request, response: Express.Response) => {
    response.sendFile(process.cwd() + "/dist/index.html");
});

app.use(Express.static("./dist/"));

const server = app.listen(3210, () => {
    console.log("Listening to port 3210");
});

const io = SocketIO.listen(server);
最后一行导致了后面提到的问题

共同响应的
webpack.config.js

module.exports = [
    {
        entry: "./server/main.ts",
        output: {
            path: "./dist",
            filename: "server.js"
        },
        debug: true,
        devtool: "source-map",
        module: {
            loaders: [
                {
                    test: /\.ts$/,
                    loader: "ts-loader"
                }
                , {
                    test: /\.json/,
                    loader: "json-loader"
                }
            ]
        },
        target: "node",
        node: {
            fs: "empty",
            net: "empty"
        }
        ts: {
            configFileName: 'server.tsconfig.json'
        }
    }
];
但在最后,
webpack
打印出以下警告:

./~/express/lib/view.js中的警告

关键依赖项:

78:29-56依赖项的请求是一个表达式

@./~/express/lib/view.js 78:29-56

./~/socket.io/~/engine.io/lib/server.js中的警告

关键依赖项:

75:43-65依赖项的请求是一个表达式

@./~/socket.io/~/engine.io/lib/server.js 75:43-65

./~/socket.io/~/engine.io/~/ws/lib/Validation.js中的警告

未找到模块:错误:无法解析…\node\u modules\socket.io\node\u modules\engine.io\node\u modules\ws\lib中的模块“utf-8-validate”

@../~/socket.io/~/engine.io/~/ws/lib/Validation.js 10:19-44

./~/socket.io/~/engine.io/~/ws/lib/BufferUtil.js中的警告

未找到模块:错误:无法解析…\node\u modules\socket.io\node\u modules\engine.io\node\u modules\ws\lib中的模块“bufferutil”

@../~/socket.io/~/engine.io/~/ws/lib/BufferUtil.js 10:19-40

./~/socket.io/~/socket.io client/~/engine.io client/~/ws/lib/Validation.js中出现警告

未找到模块:错误:无法解析…\node\u modules\socket.io\node\u modules\socket.io client\node\u modules\engine.io client\node\u modules\ws\lib中的模块“utf-8-validate”

@../~/socket.io/~/socket.io client/~/engine.io client/~/ws/lib/Validation.js 10:19-44

./~/socket.io/~/socket.io client/~/engine.io client/~/ws/lib/BufferUtil.js中出现警告

未找到模块:错误:无法解析…\node\u modules\socket.io\node\u modules\socket.io client\node\u modules\engine.io client\node\u modules\ws\lib中的模块“bufferutil”

@../~/socket.io/~/socket.io client/~/engine.io client/~/ws/lib/BufferUtil.js 10:19-40

进程已终止,代码为0

运行server.js会导致:

js:549返回binding.open(pathModule.\u makeLong(path)、stringToFlags(flags)、mode)

TypeError:路径必须是字符串

有人知道我做错了什么吗

import * as SocketIO from "socket.io";
应该是:

import SocketIO from "socket.io-client";
应该是:

import SocketIO from "socket.io-client";

像这样尝试
const io=SocketIO(服务器)我尝试了这个,但这给了我一个传输时间错误。可能Typescript定义文件
“socket.io:“registry:dt/socket.io#1.4.4+20160909205835”
被Corupped。?向我们展示所谓的
传输时间错误
@JaganathanBantheswaran这是以“/~/express/lib/view.js”开头的第一个引号@带有
传输时间错误的Jaganathanbanthessaran
我指的是来自Web包的错误消息和警告我尝试了这个,但这给了我一个传输时间错误。可能Typescript定义文件
“socket.io:“registry:dt/socket.io#1.4.4+20160909205835”
被Corupped。?向我们展示所谓的
传输时间错误
@JaganathanBantheswaran这是以“/~/express/lib/view.js”开头的第一个引号@JaganathanBantheswaran带有
传输时间错误
我指的是来自webpack的错误消息和警告。