fs.existsSync在电子中使用时不起作用 [英] fs.existsSync is not a function when used in electron
问题描述
我正在使用 Angular 10
, Electron 10.0
和 electron-builder v22.8.0
.
启动我的Electron应用程序时,我在控制台中收到以下错误:
When starting my Electron app, I receive the following error in the console:
fs.existsSync is not a function when used in electron
getElectronPath @ ./node_modules/events/events.js:6
<anonymous> @ ./node_modules/events/events.js:17
./node_modules/electron/index.js @ ./node_modules/events/events.js:19
__webpack_require__ @ ./webpack/bootstrap:79
./src/app/projectview/new/new.component.ts @ ./src/app/projectview/new/new.component.ts:1
[...]
at __webpack_require__ (bootstrap: 79)
错误在这里弹出:
当我导入电子并在我的渲染器过程中包含以下行时,就会发生这种情况:
It happens when I import electron and have the following line in my renderer process:
import { remote } from 'electron';
// later on in my component:
remote.dialog.showOpenDialog(...);
创建 BrowserWindow
时,
nodeIntegration
为 true
.
[...]
win = new BrowserWindow({
webPreferences: {
webSecurity: false,
nodeIntegrationInWorker: true,
nodeIntegration: true,
allowRunningInsecureContent: (serve) ? true : false,
},
我已经浏览了整个StackOverflow,但是找不到我没有尝试过的任何解决方案.谁能帮我吗?
I have browsed entire StackOverflow, but can't find any solution I haven't tried. Can anyone help me?
推荐答案
所以根据您的句子:当我导入电子并在渲染器过程中包含以下行时会发生这种情况:从'electron'导入{remote};
是远程api的突破性变化.
Web首选项 enableRemoteModule";现在默认为false.
in electron 10 is a breaking change of the remote api.
the webpreference "enableRemoteModule" is now by default false.
激活模块并再次测试:
const w = new BrowserWindow({
webPreferences: {
enableRemoteModule: true
}
})
签出使用ipcRenderer的推荐方法:
使用ipcRenderer而不是远程
checkout the recommended way to use ipcRenderer:
use ipcRenderer and not remote
这篇关于fs.existsSync在电子中使用时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!