Aurelia start setRoot gives the error No applicationHost was specified

Viewed 134

Using the following code:

import { Aurelia } from "aurelia-framework";

export async function configure(aurelia) {
  aurelia.use.standardConfiguration().developmentLogging();

  await aurelia
    .start()
    .then(a => a.setRoot())
    //.then(a => a.setRoot("app.js", document.body))
    .catch(ex => {
      document.body.textContent = `Bootstrap error: ${ex}`;
    });
}

I get this error:

Bootstrap error: Error: No applicationHost was specified.

If I switch to use .then(a => a.setRoot("app.js", document.body)) instead of .then(a => a.setRoot()) everything works.

In Aurelias own quick start guide they use the following code:

import {Aurelia} from 'aurelia-framework';

export function configure(aurelia: Aurelia) {
    aurelia.use.basicConfiguration();
    aurelia.start().then(() => aurelia.setRoot());
}

If i switch to use.basicConfiguration in my code I still get the same error.

https://aurelia.io/docs/tutorials/creating-a-todo-app#getting-ready-to-render

Codesandbox to reproduce:

https://codesandbox.io/s/0x4wvlly90

1 Answers

In automatic bootstrapping, aurelia-bootstrapper detects elements with aurelia-app attribute, and based on the value specified, will load the main entry to bootstrap with the information about which elements host those aurelia-app attributes. That's why you can do setRoot() without any arguments. First argument is app.js, and the second argument is automatically supplied by the above detection.

When you do manually bootstrapping like in the question code block, there is no information about root, thus the error as you saw. So it's correct, and standard way to do it that you are supplying the 2nd parameter.

Related