我对 Angular、Javascript 等话题还很陌生。
我尝试编写一个应该访问文件系统的 (TypeScript) Angular2-Electron 应用程序。每个人都只是说需要“fs”模块,一切都很好,但这对我不起作用……。
如果我这样做:var fs = require('fs');
我可以看到我的应用程序尝试从我的应用程序根文件夹加载“fs”模块: ..myapp/dist/fs net::ERR_FILE_NOT_FOUND
我的所有其他外部模块都在 index.html 中引用:
<!-- build:js app/scripts/combined.js -->
<script src="../node_modules/jquery/dist/jquery.js"></script>
<script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../node_modules/systemjs/dist/system.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/http.js"></script>
<script src="../node_modules/angular2/bundles/router.js"></script>
<script src="../node_modules/rxjs/bundles/Rx.js"></script>
<script src="../node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script src="../node_modules/pdfjs-dist/build/pdf.combined.js"></script>
<script src="boot.js" type="text/javascript"></script>
<!-- endbuild -->
因此我认为可以找到它们,但是“fs”属于 Electron 中存在的 node.js?还是我在思想上犯了一些大错误?
非常感谢,
克里斯
最佳答案
问题似乎是我在 Angular 应用程序中使用了 SystemJS。 SystemJS 尝试从我自己的应用程序加载模块。
我现在添加了这个,所以我的 index.html 似乎可以工作了:
<script>
if (require) {
window.$ = window.jQuery = require('./app/assets/js/jquery.min.js');
window.fs = require('fs');
window.path = require('path');
}
</script>
关于typescript - Electron ,Angular2, "fs",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663454/