Electron、Angular2、“fs" [英] Electron, Angular2, "fs"
问题描述
我对 Angular、Javascript 等主题非常陌生.
I am very new to the topic of Angular, Javascript etc.
我尝试编写一个 (TypeScript) Angular2-Electron 应用程序,它应该可以访问文件系统.每个人都只是说需要fs"模块,一切都很好,但这对我不起作用...... .
I try to write a (TypeScript) Angular2-Electron application which should access the file-system. Everyone just says to require the "fs" module and all is fine, but that doesn't work for me... .
如果我这样做:var fs = require('fs');
我可以看到我的应用程序尝试从我的应用程序根文件夹加载该fs"模块:..myapp/dist/fs net::ERR_FILE_NOT_FOUND
I can see that my app tries to load that "fs" module from my app root folder: ..myapp/dist/fs net::ERR_FILE_NOT_FOUND
我所有的其他外部模块都在 index.html 中引用:
All my other external modules are referenced in the 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"属于电子中存在的 node.js?还是我的想法犯了一些大错误?
And therefore I think they could be found, but "fs" belongs to node.js which is present in electron? Or have I made some big mistakes in my thoughts?
非常感谢,
克里斯
Thanks a lot,
Chris
推荐答案
问题似乎是我在 Angular 应用程序中使用 SystemJS.SystemJS 尝试从我自己的应用程序中加载模块.
The problems seems to be that i use SystemJS in my Angular Application. SystemJS tries to load the modules from my own application.
我现在已经添加了这个,所以我的 index.html 似乎可以工作:
I now have add this so my index.html which seems to work:
<script>
if (require) {
window.$ = window.jQuery = require('./app/assets/js/jquery.min.js');
window.fs = require('fs');
window.path = require('path');
}
</script>
这篇关于Electron、Angular2、“fs"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!