Sytemjsはindex.htmlで定義されているため、技術的にはアプリケーションのどこからでもSystem.importを実行できます。しかし、ビルド時に、ダイナミックにそれが使用されているライブラリをインポートし、私のコンポーネントは、エラーを与える:ここでAureliaのアプリケーションレベルで既に定義されているライブラリを参照する方法ViewModel
error TS2304: Cannot find name 'System'
は、コンポーネントのコードは次のとおりです。
import { bindable, bindingMode, customElement, noView } from 'aurelia-framework';
@noView()
@customElement('scriptinjector')
export class ScriptInjector {
@bindable public url;
@bindable public isLocal;
@bindable public isAsync;
@bindable({ defaultBindingMode: bindingMode.oneWay }) protected scripttag;
private tagId = 'bootTOCscript';
public attached() {
if (this.url) {
if (this.isLocal) {
System.import(this.url);
return;
}
this.scripttag = document.createElement('script');
if (this.isAsync) {
this.scripttag.async = true;
}
this.scripttag.setAttribute('src', this.url);
document.body.appendChild(this.scripttag);
}
}
public detached() {
if (this.scripttag) {
this.scripttag.remove();
}
}
}
プロジェクトはもかかわらず、ちょうど罰金を構築し、実行します
import System from 'systemjs';
をエラーを解決しますが、実行時に、このインポートがSystemjsアプリビルド府に自分自身を探すために、原因部品に:エラーと私は追加することでこれを解決しようとしましたこれは間違っています。 System.jsコードは別々にエクスポートされます。これを解決し、エラーメッセージがなく、実行時に動作する方法がありますか?
ありがとう(システムの実際の型は、あなたの.d.tsがどのように見えるかに依存します)、これはうまくいった。小さなフォローアップ、この他の答えは、グローバルウィンドウオブジェクトに新しいプロパティが追加された別の問題を助けました:https://stackoverflow.com/a/12709880/229250 – Bitfiddler