typeScript 中的 systemjs 模块:XHR 错误

systemjs module in typeScript: XHR error

错误:
GET http://localhost:63342/Dog.js 404 (Not Found)
XHR error (404 Not Found) 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"
  ]
}        

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

尝试将您的 html 更改为:

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

System.defaultJSExtensions = true;

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

希望对您有所帮助。