typeScript中的systemjs模块:XHR错误

时间:2016-02-05 04:35:48

标签: typescript systemjs

错误:
获取http://localhost:63342/Dog.js 404(未找到)
XHR错误(404未找到)loading http://localhost:63342/Dog.js

             <br/><br/>Here is my script in index.html.                                                                              <script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.src.js"></script>

<script>
    // set our baseURL reference path
    System.config({
        baseURL: '.'
    });

    System.import('Dog.js').catch(console.log.bind(console));
</script> 

Animal.ts

export class Animal {
    color: string;
    age: number;

    constructor(color: string, age:number) {
        this.color = color;
        this.age = age;
    }

    add(animal: Animal) {
        return new Animal(this.color + animal.color, this.age + animal.age);
    }
}

Dog.ts

import {Animal} from './Animal';

var animal1 = new Animal("red", 1);
var animal2 = new Animal("yellow", 2);
var animal3 = animal1.add(animal2);
console.log('Combine Two Animals' + animal3); 

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": false
  },
  "exclude": [
    "node_modules"
  ]
}        

以上所有文件都在同一个文件夹中。

1 个答案:

答案 0 :(得分:3)

尝试将您的HTML更改为:

System.config({
    baseURL: '.'
});

System.defaultJSExtensions = true;

System.import('Dog').catch(console.log.bind(console));

希望这有帮助。