首页 > 解决方案 > 使用流星套接字 io 启动失败

问题描述

我想用 socket.io 设置一个流星应用程序,并使用https://github.com/Akryum/meteor-socket-io中的示例并以这种方式安装所有内容。当我想启动流星比时,我收到错误消息:

启动时 TypeError: socket_io.server is not a function

我尝试以不同的方式导入 socket_io,但我是流星的绝对新手(第一个应用程序......),解决方案可能很明显

正如我试过的 github-project 给出的那样

// Meteor Socket from https://github.com/Akryum/meteor-socket-io
import http from 'http';
import socket_io from 'socket.io';

const PORT = 8080;

Meteor.startup(() => {

  // Server
  const server = http.createServer();
  const io = socket_io(server);

...

产生的错误信息是:

W20190912-17:07:15.698(2)? (STDERR) /home/fips/.meteor/packages/meteor-tool/.1.8.1.ani1yi.p0f9s++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20190912-17:07:15.698(2)? (STDERR)                                             throw(ex);
W20190912-17:07:15.698(2)? (STDERR)                                             ^
W20190912-17:07:15.699(2)? (STDERR) 
W20190912-17:07:15.699(2)? (STDERR) TypeError: socket_io.server is not a function
W20190912-17:07:15.699(2)? (STDERR)     at Meteor.startup (server/main.js:15:24)
W20190912-17:07:15.699(2)? (STDERR)     at Function.time ([...removed...]/.meteor/local/build/programs/server/profile.js:309:28)
W20190912-17:07:15.699(2)? (STDERR)     at [...removed...]/.meteor/local/build/programs/server/boot.js:435:13
W20190912-17:07:15.699(2)? (STDERR)     at [...removed...]/.meteor/local/build/programs/server/boot.js:480:5
W20190912-17:07:15.700(2)? (STDERR)     at Function.run [...removed...]/.meteor/local/build/programs/server/profile.js:510:12)
W20190912-17:07:15.700(2)? (STDERR)     at [...removed...]/.meteor/local/build/programs/server/boot.js:478:11
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

我认为(!)我理解为什么它不是一个函数,但我不知道如何调用 socket_io 否则。

标签: javascriptsocketsmeteorsocket.io

解决方案


推荐阅读