2016-03-18 32 views
6

私のプロジェクトのシードとしてangular2-seedを使用しています。 requireはソースファイルで完璧に動作しています。しかし、私が新しいライブラリをインクルードしてindex.htmlで参照すると、コンソールにはrequireが定義されていないというエラーが表示されます。node_modulesのライブラリでAngular2のrequireが定義されていません

Systemjsは私ががsystem.jsを使用することを示唆してSOに以前の回答を読んだ

が含まれています。 systemjsは既に含まれています。

Index.htmlと

<!-- shims:js --> 
 
<script src="/node_modules/systemjs/dist/system.src.js?1458283463580"></script> 
 
<script src="/node_modules/systemjs/dist/system-polyfills.src.js?1458283463581"></script> 
 
<script src="/node_modules/reflect-metadata/Reflect.js?1458283463582"></script> 
 
<script src="/node_modules/es6-shim/es6-shim.js?1458283463582"></script> 
 
    <script src="/node_modules/angular2/bundles/angular2-polyfills.js?1458283463582"></script> 
 
<!-- endinject --> 
 

 
    
 
<script>System.config({"defaultJSExtensions":true,"paths":{"./admin/main":"/./admin/main","angular2/*":"/angular2/*","rxjs/*":"/rxjs/*","*":"/node_modules/*"},"packages":{"angular2":{"defaultExtension":false},"rxjs":{"defaultExtension":false}},"map":{"moment":"moment/moment.js"}})</script> 
 
    
 

 
<!-- libs:js --> 
 
<script src="/node_modules/rxjs/bundles/Rx.js?1458283463585"></script> 
 
<script src="/node_modules/angular2/bundles/angular2.js?1458283463585"></script> 
 
<script src="/node_modules/angular2/bundles/router.js?1458283463585"></script> 
 
<script src="/node_modules/angular2/bundles/http.js?1458283463586"></script> 
 
<script src="/node_modules/ng2-bootstrap/ng2-bootstrap.js?1458283463586"></script> 
 
<script src="/node_modules/ng2-select/ng2-select.js?1458283463586"></script> 
 
<script src="/node_modules/lodash/index.js?1458283463587"></script> 
 
<script src="/node_modules/ng2-pagination/index.js?1458283463587"></script> 
 
<!-- endinject --> 
 

 
<!-- inject:js --> 
 
<!-- endinject --> 
 

 
    
 
<script> 
 
System.import('./admin/main') 
 
    .catch(function (e) { 
 
    console.error(e, 
 
     'Report this error at https://github.com/punchagency/staffing-client/issues'); 
 
    }); 
 
</script>

が使用されている必要が

エラー

enter image description here

ソースlodash

module.exports = require('./lodash'); 

index.jsは同様ng2-selectng2-bootstrapのような他のライブラリには、あなたがSystemJSにあなたの追加の依存関係を設定し、scriptタグに直接それらを含めないようにする必要があります同様のエラー

答えて

4

を持っています。ここで

はサンプルです:

<script> 
    System.configure({ 
    map: { 
     'ng2-bootstrap': 'node_modules/ng2-bootstrap', 
     'ng2-select': 'node_modules/ng2-select', 
     lodash: 'node_modules/lodash/lodash.js' 
    }, 
    package: { 
     (...) 
    } 
    }); 
    System.import(...); 
</script> 

は、より多くの詳細については、これらの質問を参照してください:

+0

をロット@Theirry、systemConfigソリューションが動作しているおかげで。しかし、lodash/lodash.jsの代わりにlodash/index.jsを追加すると、requireエラーが再び発生します。 lodashのindex.jsには、この 'module.exports = require( './lodash');' ........なぜlodash.jsが動作し、index.js ....ではないのですか? – hhsadiq

関連する問題