Electron + jpeg-turbo (native module)


#1

I’m trying to get Electron to work properly with jpeg-turbo. I’ve managed to get other native modules to work using the steps below, but so far no luck with jpeg-turbo.

This is what I’ve done:

  1. Clone the Electron quickstart repo: git clone https://github.com/electron/electron-quick-start.git
  2. npm install jpeg-turbo
  3. Either install and run electron-rebuild or set the environment variables as per these instructions: https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md
  4. Require jpeg-turbo from somewhere within the quickstart code, in renderer.js for instance.
  5. Run the app

This results in the following error message for me:

Uncaught Error: Cannot find module '/Users/tommypreger/Desktop/test1/node_modules/jpeg-turbo/lib/binding/node-v64-darwin-x64/jpegturbo.node'

When looking in the node_modules/jpeg-turbo/lib/binding folder I can tell that electron-rebuild has created a new folder called electron-v3.0-darwin-x64, but as you can see in the error message, it’s trying to resolve the module in a folder node-v64-darwin-x64 (which does not exist)

It seems I can actually rename the folder manually and get the module to work, but that feels like a horrible hack.

Jpeg-turbo’s package.json file includes the following clue:

"binary": { "module_path": "./lib/binding/{node_abi}-{platform}-{arch}", }

I’m assuming this is what points the electron process to the wrong folder when requiring it?

Does anyone know the proper solution to this problem?

Thanks in advance!