2017-01-05 12 views
3

SystemJSでjQueryをプロジェクトにインポートする方法を理解できません。 のindex.html:SystemJSでjqueryをインポートできません

... 
<script> 
    System.import('app').catch(function(err){ console.error(err); }); 
    System.import('jquery').catch(function(err){ console.error(err); }); 
    System.import('bootstrap').catch(function(err){ console.error(err); }); 
</script> 
... 

エラー:

(インデックス):26エラー:(SystemJS)ブートストラップのJavaScriptは、jQueryの エラーが必要です。ブートストラップのJavaScriptはevalを

systemjs.configでのjQuery が必要です。 js

(function (global) { 
    System.config({ 
    paths: { 
     // paths serve as alias 
     'npm:': 'node_modules/' 
    }, 
    // map tells the System loader where to look for things 
    map: { 
     // our app is within the app folder 
     app: 'app', 

     // angular bundles 
     ... 

     'jquery': "npm:jquery/dist/jquery.min.js", 
     'bootstrap': "npm:bootstrap/dist/js/bootstrap.min.js", 

     // other libraries 
     'rxjs':      'npm:rxjs' 
    }, 
    // packages tells the System loader how to load when no filename and/or no extension 
    packages: { 
     app: { 
     main: './main.js', 
     defaultExtension: 'js' 
     }, 
     rxjs: { 
     defaultExtension: 'js' 
     } 
    } 
    }); 
})(this); 
+0

SystemJSを使用している場合は、JSPMにも行く必要があります。手動でSystemJSファイルを設定することは避けます... –

答えて

1

これは、ブートストラップが最初にインポートされているために発生しています。

インポートは非​​同期です。 1つはもう一方の前にインポートすることができます。注文を強制するには

System.import('jquery') 
.then(function($) { 
    System.import('bootstrap'); 
}) 
.catch(function(err){ console.error(err); }); 
関連する問題