Aurelia 使用 featherjs 依赖项无法正确导入 feathers-socketio

Aurelia using featherjs dependency failing to properly import feathers-socketio

如何使用 Aurelia 项目中常见的技术导入 featherjs-socketio。之前的一个问题帮助我克服了第二个依赖项,但最后一个问题似乎与第一个没有类似解决方法的命运相同。

这是我的:

在构建文件中aurelia.json

"dependencies": [
          {
            "name": "socket.io-client",
            "path": "../node_modules/socket.io-client/dist/socket.io.min"
          },
          {
            "name": "feathers-client",
            "path": "../node_modules/feathers-client/dist",
            "main": "feathers"
          },
          {
            "name": "feathers-socketio",
            "path": "../node_modules/feathers-socketio",
            "main": "client"
          },
          "aurelia-binding",

在app.js

import io from 'socket.io-client';
import feathers from 'feathers';
import socketio from 'feathers-socketio';

export class App {
  constructor() {
    this.message = 'Hello World!';

    console.log("startup"); 

    const socket = io('http://localhost:3030');

    const app = feathers()
      .configure(socketio(socket));
  }
}

错误如下所示:

Starting 'readProjectConfiguration'...
Finished 'readProjectConfiguration'
Starting 'processMarkup'...
Starting 'processCSS'...
Starting 'configureEnvironment'...
Finished 'processCSS'
Finished 'processMarkup'
Finished 'configureEnvironment'
Starting 'buildJavaScript'...
Finished 'buildJavaScript'
Starting 'writeBundles'...
Tracing app...
{ uid: 8,
  name: 'writeBundles',
  branch: false,
  error: 
   { [Error: ENOENT: no such file or directory, open '/Users/steve/project/src/feathers-socket-commons/client.js']
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/Users/steve/project/src/feathers-socket-commons/client.js',
     moduleTree: [ 'feathers-socketio/lib/client' ],
     fileName: '/Users/steve/project/node_modules/feathers-socketio/lib/client.js' },
  duration: [ 0, 281071327 ],
  time: 1484922063672 }

一旦它开始处理依赖项,它似乎在寻找 featherjs-socketio 中的依赖项时出现路径混乱。我问了一个关于羽毛依赖的问题,这个问题已经解决了,但不知道如何处理这个问题。

feathers-socket-commons 在节点模块中列出,但它似乎在我的项目文件夹中查找,所以这就是为什么我假设它在路径上混淆,或者根本不是客户端库?奇怪,因为示例显示使用此节点模块,但示例还显示使用 'feathers' 而不是 'feathers-client'。这是feathers-socketio中给出的客户端示例:

客户端使用

import io from 'socket.io-client';
import feathers from 'feathers/client';
import socketio from 'feathers-socketio/client';

const socket = io('http://path/to/api');
const app = feathers()
  .configure(socketio(socket));

解决方案感谢下面标记的答案。

aurelia.json 更改为:

"dependencies": [
          {
            "name": "socket.io-client",
            "path": "../node_modules/socket.io-client/dist/socket.io.min"
          },
          {
            "name": "feathers-client",
            "path": "../node_modules/feathers-client/dist",
            "main": "feathers"
          },
          "aurelia-binding",

app.js 变为:

import io from 'socket.io-client';
import feathers from 'feathers-client';

export class App {
  constructor() {
    this.message = 'Hello World!';

    console.log("startup");

    const socket = io('http://localhost:3030');

    const app = feathers().configure(feathers.socketio(socket));
  }
}

您不需要安装 feathers-socketio 它包含在 feathers-client 等插件中。

configure(socketio(socket))

变为:

configure(feathers.socketio(socket))

根据feathers-socketio