Theia Electron: plugin Node version mismatching


I’m developing a backend plugin for theia application. This plugin use the serialport npm library.
When I run Theia as browser , no problem. The plugin work fine.
But when I try to run plugin on Theia as Electron app, it raise an error during the boot phase:

root ERROR [hosted-plugin: 18029] Error: The module '/theia/theia-ide-dev/theia/plugins/web-app-plugin/node_modules/@serialport/bindings/build/Release/bindings.node' <br>
was compiled against a different Node.js version using
NODE_MODULE_VERSION 64. This version of Node.js requires
NODE_MODULE_VERSION 69. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:160:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:722:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:160:31)
    at Module.load (internal/modules/cjs/loader.js:602:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:541:12)
    at Function.Module._load (internal/modules/cjs/loader.js:533:3)
    at Function.module._load (/theia/theia-ide-dev/theia/packages/plugin-ext-vscode/lib/node/plugin-vscode-init.js:80:33)
    at Function.module._load (/theia/theia-ide-dev/theia/packages/plugin-ext/lib/hosted/node/scanners/backend-init-theia.js:42:33)
    at Module.require (internal/modules/cjs/loader.js:640:17)
    at require (internal/modules/cjs/helpers.js:20:18)`

I tried to use electron-rebuild in order to fix this issue, unsuccessfully.
So , my question is: there is a way to build plugin being aware of electron node version?


[original thread by davide-sergi]

@davide-sergi can you try running the command yarn rebuild:eletron before starting the application (when using electron as a target).

I believe you might have encountered a problem similarly to:


yeah. I just tried, with this output
$ theia rebuild:electron native node modules are already rebuilt for electron :sparkles: Done in 0.47s.

It might help to do a clean and rebuild as mentioned in the issue I referenced.
In my experience I rarely encountered the issue when switching between the browser and electron targets.


Hi! I thought I’d chime in since I had the exact same problem with Node versions. Yarn theia rebuild:electron did nothing for me, unfortunately. Even after running clean and rebuilding. I’d always get the same message, that the native node modules are already built for electron and the application wouldn’t start up. However, after I added electron-rebuild as a dev dependency (v. 1.10.1) and running yarn electron-rebuild my application started up without any problems. @davide-sergi If I understood you correctly, you tried the same approach, but it didn’t help? Well, I’m going to leave this here just in case. Hopefully it will help somebody else.


Thanks very much. I done exactly what you have reported. Anyway, my theia electron app starts and I can use it. The only problem is the plugin. It seems fail at boot time. I think that the problem is related to the serialport library I’m using.