电子,Angular2,"fs" [英] Electron, Angular2, "fs"

查看:60
本文介绍了电子,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');

If I do something like: 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>

这篇关于电子,Angular2,"fs"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆