I'm trying to add the AutobahnJS library to my Aurelia application which is using the new aurelia-cli requirejs-based dependency management feature.
After installing autobahn using npm:
npm install autobahn
And then editing aurelia.json
to provide more information about the structure of the NPM module (in vendor-bundle.js
section):
{
"name": "autobahn",
"path": "../node_modules/autobahn/lib",
"main": "autobahn"
}
The application will not start (au run --watch
), due to this (abbreviated) error:
// snip...
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/Users/hozn/workspace/my-ui/autobahn/polyfill.js',
moduleTree: [ 'autobahn/autobahn' ],
fileName: '/Users/hozn/workspace/my-ui/node_modules/autobahn/lib/autobahn.js'
Looking at the source of node_modules/autobahn/lib/autobahn.js
there are multiple require('./<module>.js'
lines, such as:
var util = require('./polyfill.js');
Apparently the aurelia-cli
bundler/runner is assuming those would be relative to my application's root directory rather than the autobahn module's installed directory. Removing the ".js" extension does seem to fix things here, though I'm not sure if that is addressing the root problem or just triggering a different lookup mechanism? I've been unable to find any other special settings to pass in the dependency declaration to allow this package to work.
So far the only thing I've gotten to work is to download one of the built versions of autobahn.js and then put this in the prepend
section of the aurelia.json
file. This is a bit of a hack, though, and I'd love to learn how to do this more correctly using aurelia-cli
.