typescript - Electron ,Angular2, "fs"

标签 typescript angular electron

我对 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/

相关文章:

javascript - 如何在 Angular 6 中实现选择下拉列表(按搜索过滤),如何按名称属性过滤对象

angular - 导出返回类 : Exported variable has or is using private name 的函数时出错

Angular 单元测试表单验证

node.js - 自动允许 Electron 应用程序的隐私

reactjs - 设置 PROPS 类型的正确方法是什么?

导出的 Angular 默认路径

javascript - 将 ngFor 循环的最后一个元素滚动到 View 中

reactjs - Electron js : Right Click is not registering

javascript - Electron 中没有定义 require 吗?

javascript - 从事件中获取 vue 组件