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

将Theia集成至现有Electron应用:找不到drivelist.node原生模块

Theia编辑器集成现有Electron应用的原生模块加载问题

我尝试将Theia编辑器集成到现有Electron应用中已近一周,但始终未能成功。所有Electron示例均展示独立运行Theia的方式,完全未提及如何将其集成至现有应用。

theia build命令会生成包含完整Theia应用的lib文件夹,这并非我所需的集成形式。

我的现有BrowserWindow已启用contextIsolation,Theia有一个即将合并至master分支的PR(支持contextIsolation)。假设该PR很快合并,我计划忽略@theia/electron,转而在Electron主进程中启动面向浏览器的Theia BackendApplication(来自@theia/core/lib/node/backend-application-module)。由于我的BrowserWindow因contextIsolation无法访问Node运行时,前端应用可像在浏览器环境中一样与该服务器通信。

我认为这个集成路径是正确的,但在协调已编译原生模块的位置时遇到了问题。我在Electron的main.ts中添加了以下极简Theia代码:

require('reflect-metadata');
const { Container } = require('inversify')
const { backendApplicationModule } = require('@theia/core/lib/node/backend-application-module');
const container = new Container();
container.load(backendApplicationModule);

运行应用时出现如下错误:

Uncaught Exception:
Error: Could not locate the bindings file. Tried:
→ /Users/admin/code/client/app/build/drivelist.node
→ /Users/admin/code/client/app/build/Debug/drivelist.node
→ /Users/admin/code/client/app/build/Release/drivelist.node
→ /Users/admin/code/client/app/out/Debug/drivelist.node
→ /Users/admin/code/client/app/Debug/drivelist.node
→ /Users/admin/code/client/app/out/Release/drivelist.node
→ /Users/admin/code/client/app/Release/drivelist.node
→ /Users/admin/code/client/app/build/default/drivelist.node

我的Electron应用使用electron-builder install-app-deps编译原生模块,我也清楚Theia需要为浏览器或Electron环境编译部分原生模块。

执行theia rebuild:browser后得到提示:native node modules are already rebuilt for browser,但我找不到编译后的文件位置。

执行theia rebuild:browser && theia rebuild:electron后,生成了新的.browser_modules文件夹,其中确实包含所需的drivelist.node模块。

但应用加载时显然未检查这个位置,仍然找不到drivelist.node。

我的Electron应用通过webpack编译,配置了相关的node-loader:

{
     test: /.node$/,
     loader: 'node-loader',
}

该配置可正常加载Electron应用自身的原生模块,但添加Theia代码后,无法找到.browser_modules中明确存在的drivelist.node。我尝试过多种node-loader配置,均未解决问题。

内容的提问来源于stack exchange,提问作者parliament

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 04:28:15