Person.ts:打字稿 - 單模例如失敗
export class Person {
private _name: string;
constructor(name: string) {
this._name = name;
}
get name(): string {return this._name};
}
test.ts:
import {Person} from "./Person";
var user = new Person("John");
document.getElementById("h1").innerHTML = user.name;
tsconfig.json:
{
"compilerOptions": {
"target": "es5"
,"outDir" : "build"
}
}
當在瀏覽器打開所述結果,控制檯上顯示以下錯誤:
Uncaught ReferenceError: exports is not defined
at test.js:2
看到此評論 http://stackoverflow.com/a/33294807/4096589 瀏覽器不知道CommonJS的模塊 – radix
您正在使用哪種瀏覽器?也許你錯過了一個polyfill :) – Digvijay