Search code examples
typescriptcomponentsaurelia

Why is Aurelia looking in the wrong place for it's files?


Iv'e decided to have a go at building an app using Aurelia, and on the whole I really like what I see.

However, I'm having severe problems trying to use the built in functionality that comes with the framework.

After 2 days of wrestling with package managers and config files, I've finally gotten my build (Typescript) to recognise that I have the aurelia-http-client library installed, but I cannot for the life of me get "au build" to look in the correct place for it (Well not without specifying the full path manually anyway)

My Component looks as follows:

import {bindable} from 'aurelia-framework';
import {HttpClient} from 'aurelia-http-client';

export class Stanoxtable {

  public getData(){

    alert("About to get data");

    let client = new HttpClient();

    client.get('http://localhost/corpus.json')
    .then(data => {
      console.log(data)
    });

  }

}

I have the following in my config.js file:

...
    paths: {
        "github:*": "jspm_packages/github/*",
        "npm:*": "jspm_packages/npm/*"
    },

    map: {
        "aurelia-http-client": "npm:[email protected]",
...

I also have the following in package.json:

...
  "devDependencies": {
    "aurelia-cli": "^0.23.0",
    "aurelia-http-client": "^1.0.3",
...
  },
  "jspm": {
    "dependencies": {
      "aurelia-http-client": "npm:aurelia-http-client@^1.0.3"
    },
...

I have the physical files in my npm node_modules directory:

Dir showing files

And yet when I run

au build

All I get is this:

Output from "au build"

If I Put the FULL path in my component template EG:

import {HttpClient} from 'd:/aurtest2/aurelia-app/node_modules/aurelia-http-client/dist/aurelia-http-client';

The build then finds the file, but I get some weird parsing errors:

Build output 2

I have absolutely no idea what to do or try next, and could use some help from the aurelia experts out there.

Thanks Shawty


Solution

  • The Aurelia CLI serves up everything from bundles that are defined in the aurelia_project\aurelia.json file. You need to add aurelia-http-client to the vendor-bundle section of the aurelia.json file.

    Work is happening currently that will automate this so that you will be able to run something like au install aurelia-http-client and the CLI will modify the aurelia.json file for you, but for now you have to modify it by hand.

    Don't quote me on the configuration, but it will probably look like this:

    {
      "name": "aurelia-http-client",
      "path": "../node_modules/aurelia-http-client/dist/amd",
      "main": "aurelia-http-client"
    }