You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron项目WebPreferences类型不兼容编译错误求助

修复Unredacter工具的Electron TypeScript编译错误:过时WebPreferences属性问题

你的两个TypeScript错误都是因为使用了Electron新版中已移除的webPreferences配置属性,直接按以下步骤修改即可:

针对错误1:移除worldSafeExecuteJavaScript属性

worldSafeExecuteJavaScript是Electron旧版本的配置项,新版中该特性已默认启用,且不再允许显式配置。直接从webPreferences对象中删除这一行:

原代码片段:

webPreferences: {
  preload: './path/to/preload.js',
  nodeIntegration: false,
  worldSafeExecuteJavaScript: true, // 移除此行
  contextIsolation: true
}

修改后:

webPreferences: {
  preload: './path/to/preload.js',
  nodeIntegration: false,
  contextIsolation: true
}

针对错误2:移除enableRemoteModule属性

enableRemoteModule在Electron 14及以上版本中已被完全废弃并移除,直接从webPreferences对象中删除该配置项:

原代码片段:

webPreferences: {
  sandbox: true,
  webSecurity: true,
  contextIsolation: true,
  webviewTag: false,
  enableRemoteModule: false, // 移除此行
  allowRunningInsecureContent: false,
  nodeIntegration: false,
  nodeIntegrationInWorker: false,
  nodeIntegrationInSubFrames: false,
  nativeWindowOpen: false,
  safeDialogs: true
}

修改后:

webPreferences: {
  sandbox: true,
  webSecurity: true,
  contextIsolation: true,
  webviewTag: false,
  allowRunningInsecureContent: false,
  nodeIntegration: false,
  nodeIntegrationInWorker: false,
  nodeIntegrationInSubFrames: false,
  nativeWindowOpen: false,
  safeDialogs: true
}

额外说明

如果修改后仍有编译问题,大概率是项目依赖的Electron版本和当前安装的版本不匹配。可以查看项目package.json中指定的Electron版本,运行npm install electron@<对应版本>来安装兼容版本,但优先推荐移除上述过时属性,这是符合Electron新版规范的修复方式。

内容的提问来源于stack exchange,提问作者Savor Graphic Design

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 05:25:05