Aurelia using featherjs dependency failing to prop

2019-07-27 08:58发布

问题:

How do you import featherjs using the style common in Aurelia projects. This is what I have:

in the build file aurelia.json

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

In the 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));
  }
}

The error looks like this:

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/uberproto.js']
     errno: -2,
     code: 'ENOENT',
     syscall: 'open',
     path: '/Users/steve/project/src/uberproto.js',
     moduleTree: [ 'feathers/lib/feathers' ],
     fileName: '/Users/steve/project/node_modules/feathers/lib/feathers.js' },
  duration: [ 0, 161365129 ],
  time: 1484844203606 }

Once it gets into processing the dependency it seems to be having path confusion looking for dependencies in featherjs. I'm pretty new with this stuff, so it is likely something simple, but I haven't figured out the correct way to include this dependency.

回答1:

I believe what you want to install is feathers-client not feathers.

npm i -S feathers-client

aurelia.json:

{
   "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"
}

app.js:

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

export class App {
    constructor() {
        const socket = io('http://localhost:3030');
        const app = feathers().configure(feathers.socketio(socket));
    }
}


回答2:

You're missing the main property. The configuration should be like this:

{
  "name": "socket.io-client",
  "path": "../node_modules/socket.io-client/dist",
  "main": "socket.io.min"
}