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>
エラー
ソースlodash
module.exports = require('./lodash');
の
index.jsは同様ng2-select
とng2-bootstrap
のような他のライブラリには、あなたがSystemJSにあなたの追加の依存関係を設定し、script
タグに直接それらを含めないようにする必要があります同様のエラー
をロット@Theirry、systemConfigソリューションが動作しているおかげで。しかし、lodash/lodash.jsの代わりにlodash/index.jsを追加すると、requireエラーが再び発生します。 lodashのindex.jsには、この 'module.exports = require( './lodash');' ........なぜlodash.jsが動作し、index.js ....ではないのですか? – hhsadiq