如何使用Aurelia项目中常见的技术导入featherjs-socketio。之前的一个问题帮助我超越了第二个依赖关系,但最后一个似乎与没有类似解决方法的第一个具有相同的命运。 Aurelia using featherjs depency failing to properly import
这就是我所拥有的:
在构建文件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 }
一旦进入处理依赖关系,它似乎在寻找dragonjs-socketio中的依赖关系时遇到路径混淆。我问过一个关于羽毛依赖性的问题已经解决了,但不知道如何处理这个问题。
feathers-socket-commons列在节点模块中,但它似乎在我的项目文件夹中查找,这就是为什么我假设它在路径上混淆,或者根本就不是客户端库?奇怪,因为示例显示使用此节点模块,但示例也显示使用'feather'而不是'feathers-client'。这是feather-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));
}
}
答案 0 :(得分:4)
您不需要安装 feathers-socketio 它包含在 feathers-client 等插件中。
when(mock.foo(anyString(), anyObject())).thenAnswer(
invocation -> {
Object argument = invocation.getArguments()[1];
if (argument.equals(new ARequest(1, "A"))) {
return new AResponse(1, "passed");
} else if (argument.equals(new ARequest(2, "2A"))) {
return new AResponse(2, "passed");
} else if (argument.equals(new BRequest(1, "B"))) {
return new BResponse(112, "passed");
}
throw new InvalidUseOfMatchersException(
String.format("Argument %s does not match", argument)
);
}
);
变为:
configure(socketio(socket))