angular - Electron and Angular : fs. existsSync 不是函数

标签 angular typescript ipc electron

我用 Angular 创建了一个新的 Electron 项目。我使用 Angular CLI 构建我的应用程序。 现在,我想从 Renderer-Process 到 Main-Process 进行通信,并在 Dev-Tools 中得到一个错误:

> Uncaught TypeError: fs.existsSync is not a function
    at Object.<anonymous> (vendor.bundle.js:72643)
    at Object.splitPathRe (vendor.bundle.js:72649)
    at __webpack_require__ (inline.bundle.js:53)
    at Object.399 (main.bundle.js:54)
    at __webpack_require__ (inline.bundle.js:53)
    at Object.400 (main.bundle.js:107)
    at __webpack_require__ (inline.bundle.js:53)
    at Object.291 (main.bundle.js:24)
    at __webpack_require__ (inline.bundle.js:53)
    at Object.473 (main.bundle.js:234)
    at __webpack_require__ (inline.bundle.js:53)
    at webpackJsonpCallback (inline.bundle.js:24)
    at main.bundle.js:1

我使用这个项目模板:https://github.com/auth0-blog/angular2-electron 重现此错误的步骤是:

git clone https://github.com/auth0-blog/angular2-electron
npm install

3.在 src/app/app.component.ts 添加如下行

const {ipcRenderer} = require('electron');

没有那一行,应用程序运行没有任何问题。 由于 Electron ,我必须以这种方式引用 ipcRenderer ... https://github.com/electron/electron/blob/master/docs/api/ipc-main.md

我不知道我做错了什么,希望你能帮助我。

最佳答案

我遇到了一个问题,下面的代码解决了它。希望也能解决你的问题。

在你的 custom.component.ts 中

declare const window: any;
declare const ipcRenderer: any;
ipcRenderer = window.require('electron');
// then you can continue what you want to do with ipcRenderer.

关于angular - Electron and Angular : fs. existsSync 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43966353/

相关文章:

javascript - 如何配置Angular4路由器的路由

android - 跨进程共享状态变量

来自 themeforest 或类似的 Angular 模板

TypeScript - 特定的字符串类型

Angular-cli 8 - 是否可以仅在 es2015 上构建?

angular - 如何在 Angular/rxjs 中使用异步管道时传递参数?

linux - 进程间通信

c - unlink() 后从 FIFO 读取

node.js - 服务器和客户端的 Package.json

Angular 2 : How to add a class based on resolution condition?