本文介绍了Aurelia使用featherjs依赖关系无法正确导入feathers-socketio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Aurelia项目中常用的技术导入featherjs-socketio.上一个问题帮助我克服了第二个依赖性,但是最后一个似乎与第一个依赖性相同,但没有类似的解决方法. 使用Featherjs依赖度的Aurelia无法正确导入

How do you import featherjs-socketio using the technique common in Aurelia projects. A previous question helped me past the second dependency, but the last one seems to have the same fate as the first without a similar workaround. Aurelia using featherjs depency failing to properly import

这就是我所拥有的:

在构建文件aurelia.json

in the build file 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中的依赖关系.我问了一个关于羽毛依赖的先前问题,该问题已解决,但不确定该如何处理.

Once it gets into processing the dependency it seems to be having path confusion looking for dependencies in featherjs-socketio. I asked a previous question about the feathers dependency which is resolved, but not sure what to do with this one.

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

feathers-socket-commons is listed in the node modules, but it seems to be looking in my project folder so that is why I'm assuming it is confused on path, or simply not a client library? Strange because the examples show using this node module, but examples also show using 'feathers' instead of 'feathers-client'. This is the client example given in 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));

解决方案.感谢以下标记的答案.

SOLUTION Thanks to the marked answer below.

aurelia.json更改为:

aurelia.json changes to:

"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 中插件.

you don't need to install feathers-socketio it is included in feathers-client among other plugins.

configure(socketio(socket))

成为:

configure(feathers.socketio(socket))

根据 feathers-socketio

这篇关于Aurelia使用featherjs依赖关系无法正确导入feathers-socketio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 13:22