Module 'compiled against a different Node.js version' for Electron

Hi there:) I’m trying to get Theia to run in Electron but get a ‘compiled against a different Node.js version’ error even after electron rebuild seeming to have run. It’s related to the package ‘better-sqlite3’. I’m using node v12.22.1 on Windows.

  • Using eclipse-theia/generator-theia-extension generate a new ‘Backend Communication’ extension (yo theia-extension)
  • In the extension directory: ‘yarn add better-sqlite3’, ‘yarn add @types/better-sqlite3 -D’
  • Use better-sqlite3 in the extension: ‘my-ext/src/node/hello-backend-service.ts’
import { injectable } from "inversify";
import { HelloBackendService } from "../common/protocol";
import * as DB from 'better-sqlite3';

@injectable()
export class HelloBackendServiceImpl implements HelloBackendService {
    sayHelloTo(name: string): Promise<string> {
        // @ts-ignore
        const db = new DB('test.db');
        return new Promise<string>(resolve => resolve('Hello ' + name));
    }
}
  • yarn
  • yarn rebuild:electron (output below)

$ theia rebuild:electron
Processing @theia/node-pty
Processing nsfw
Processing native-keymap
Processing find-git-repositories
Processing drivelist
√ Rebuild Complete
Done in 51.77s.

  • yarn start:electron (snippet from the error below)

… better_sqlite3.node’ was compiled against a different Node.js version using
NODE_MODULE_VERSION 72. This version of Node.js requires
NODE_MODULE_VERSION 80. Please try re-compiling or re-installing …

I’ve tried running electron-rebuild directly to no effect (Windows):

  • .\node_modules.bin\electron-rebuild.cmd
  • .\node_modules.bin\electron-rebuild.cmd -f -w better-sqlite3

But I can’t reproduce this with a vanilla Electron installation using the same version of electron-rebuild as Theia (also tried the latest version). So I don’t understand why ‘yarn rebuild:electron’ isn’t resolving this?

It’s hard to say anything without your code, but try something like this in your application package.json to see if it helps:

{
  "scripts": {
    "rebuild:electron": "theia rebuild:electron --modules \"@theia/node-pty\" nsfw native-keymap find-git-repositories drivelist better-sqlite3"
   }
}

Run yarn rebuild:electron. If you’re wondering why you need this, check the default rebuild list here. I hope this helps.

Thanks for your help, yes that worked :slight_smile: