aurelia / bootstrapper

Sets up the default configuration for the aurelia framework and gets you up and running quick and easy.
MIT License
75 stars 34 forks source link

createLoader promise error ignored in aurelia-bootstrapper.js #25

Closed rhencke closed 8 years ago

rhencke commented 8 years ago

If the function createLoader fails in aurelia-bootstrapper.js, its error is ignored.

A naive fix is to change https://github.com/aurelia/bootstrapper/blob/master/src/index.js#L136 to run().catch(console.error.bind(console)); but I'm not sure exactly how you'd want errors here to be handled - that change at least worked for me to diagnose the underlying error.

EisenbergEffect commented 8 years ago

What is the easiest way to reproduce this error?

EisenbergEffect commented 8 years ago

I've tried a few things but I always see the error in the console, at least in Chrome. If you can provide a bit more information, we can move forward trying to improve this.

rhencke commented 8 years ago

I'm pretty sure what I'm trying is not something you're officially supporting, but... :)

What I'm attempting to do is write an application using Electron. (basically, if you squint, it's Chromium + Node = desktop GUI apps)

My attempt that was producing this error was to use Node's native require() with Aurelia, which seemed like a good fit at first glance. However, the form of require the bootstrapper wished to see at https://github.com/aurelia/bootstrapper/blob/master/src/index.js#L51 expected the ability to do the require asynchronously, which Node does not support.

I can put up a Gist later tonight with a minimal reproduction, if that helps?

EisenbergEffect commented 8 years ago

Well, we definitely support Aurelia + Electron. I and a number of members of the community have done that successfully. However, you will still want to use system.js. Basically, let system.js handle your client modules and let node's require handle everything else. You can use them together. In one of my projects, I actually wrote a system.js plugin so I could use native es6 imports on the client side and "redirect" them to node. Here's the plugin source:

System.set('npm', System.newModule({
  'fetch': function(load, fetch) {
    var id = load.name.substring(0, load.name.indexOf('!'));
    load.metadata.requiredModule = require(id);
    return '';
  },
  'instantiate':function(load) {
    return load.metadata.requiredModule;
  }
}));

I put that in my main.js file before anything else ran. Then I used it in my code like this:

import fs from 'fs!npm';
import path from 'path!npm';
import shell from 'shell!npm';
import clipboard from 'clipboard!npm';
import ChildProcess from 'child_process!npm';
import wrench from 'wrench!npm';
rhencke commented 8 years ago

Oh, wow, thanks - I appreciate the example! I'll bite the bullet and kick things over to System.js and go with that.