无法使用remote.dialog()显示对话框或在electron / angular-cli app

时间:2017-09-18 00:21:25

标签: webpack electron angular-cli

我正在尝试从渲染器进程显示对话框。谷歌搜索时,我发现我必须const dialog = remote.dialog。尝试dialog.showErrorBox("error","this is error")时,我在渲染器模块fs.existsSync is not a function中收到错误。请让我知道如何在渲染器过程中显示对话框。我试过,对主函数进行IPC调用。但是,当我拨打ipcRenderer.send()ipcRenderer.sendSync()时,我会收到同样的错误fs.existsSync is not a function。我的bootstrapfile.ts文件如下:

import { enableProdMode, Provider } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from '/path/to/app.module';
import {remote} from 'electron';
remote.dialog.showErrorBox("Error", "An error occured");

platformBrowserDynamic().bootstrapModule(AppModule, ... )

这是控制台上的堆栈跟踪:

Uncaught TypeError: fs.existsSync is not a function
    at Object.<anonymous> (vendor.bundle.js:505)
    at Object.../../../../electron/index.js (vendor.bundle.js:511)
    at __webpack_require__ (inline.bundle.js:55)                
    at Object.../../../../../src/main.ts (main.bundle.js:1507)
    at __webpack_require__ (inline.bundle.js:55)                
    at Object.1 (main.bundle.js:1531)                           
    at __webpack_require__ (inline.bundle.js:55)                
    at webpackJsonpCallback (inline.bundle.js:26)               
    at main.bundle.js:1                                         

我试图调试发生了什么。我在main.bundle.js和vendor.bundle.js中注意到以下内容 在堆栈跟踪的帧at Object.../../../../../src/main.ts (main.bundle.js:1507)处,生成的代码如下:

/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_electron__ = __webpack_require__("../../../../electron/index.js");  

在第at Object.<anonymous> (vendor.bundle.js:505)帧处,生成的代码为

var fs = __webpack_require__("../../../../node-libs-browser/mock/empty.js");
if (fs.existsSync(pathFile)) {....}

显然,变量fs为空,导致异常。我不确定这里发生了什么。有人可以帮我理解发生了什么,我在这里出了什么问题?我还想知道如何从electron / angular-cli应用程序中显示对话框。

0 个答案:

没有答案