2016-11-25 7 views
1

expressjsを持つtypecriptで書かれたノードサーバーでsocket.io経由でWebソケットを利用しようとしていました。 webpackにバンドルされています。webpackにバンドルされているtypescriptでsocket.ioを使用したときのランタイムエラー

サーバー・コードは以下のようになります。

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"); 
}); 

const io = SocketIO.listen(server); 

最後の行は、後述の問題が発生します。

coresponding webpack.config.js

WARNING in ./~/express/lib/view.js

Critical dependencies:

78:29-56 the request of a dependency is an expression

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

WARNING in ./~/socket.io/~/engine.io/lib/server.js

Critical dependencies:

75:43-65 the request of a dependency is an expression

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

WARNING in ./~/socket.io/~/engine.io/~/ws/lib/Validation.js

Module not found: Error: Cannot resolve module 'utf-8-validate' in ...\node_modules\socket.io\node_modules\engine.io\node_modules\ws\lib

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

WARNING in ./~/socket.io/~/engine.io/~/ws/lib/BufferUtil.js

Module not found: Error: Cannot resolve module 'bufferutil' in ...\node_modules\socket.io\node_modules\engine.io\node_modules\ws\lib

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

WARNING in ./~/socket.io/~/socket.io-client/~/engine.io-client/~/ws/lib/Validation.js

Module not found: Error: Cannot resolve module 'utf-8-validate' in ...\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\lib

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

WARNING in ./~/socket.io/~/socket.io-client/~/engine.io-client/~/ws/lib/BufferUtil.js

Module not found: Error: Cannot resolve module 'bufferutil' in ...\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\lib

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

Process terminated with code 0.

でserver.js実行結果::

fs.js:549 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);

TypeError: path must be a string

....

は誰もが知ってい

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プリントで

私は何を間違えたの?

+0

この 'のconst IO = SocketIO(サーバー)のように試してみてください;' – Thaadikkaaran

+0

私はこれを試してみましたが、これは私のtranspile時間の誤差を与えました。たぶんtypescript定義ファイル '' socket.io '': "registry:dt/socket.io#1.4.4 + 20160909205835" 'が補完されていますか? –

+0

私たちに、いわゆる「蒸散時間エラー」を表示します。 – Thaadikkaaran

答えて

0
import * as SocketIO from "socket.io"; 

は次のようになります。

import SocketIO from "socket.io-client"; 
関連する問題