Search code examples
node.jstensorflowelectronelectron-forge

Tensorflow JS & Electron Forge - Error importing tensorflow js after npm run make


I have built this little app with tensorflow js. I can run it perfectly on Windows 10 using the npm start, however after I successfully run npm run make it becomes impossible to import tensorflow. I get the following error:

Uncaught Error: The specified module could not be found. \\?\C:\Users\teste\AppData\Local\my-app\app-1.0.0\resources\app.asar.unpacked\node_modules\@tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node
    at process.func (electron/js2c/asar.js:140)
    at process.func [as dlopen] (electron/js2c/asar.js:140)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1016)
    at Object.func (electron/js2c/asar.js:140)
    at Object.func [as .node] (electron/js2c/asar.js:149)
    at Module.load (internal/modules/cjs/loader.js:816)
    at Module._load (internal/modules/cjs/loader.js:728)
    at Module._load (electron/js2c/asar.js:717)
    at Function.Module._load (electron/js2c/asar.js:717)
    at Module.require (internal/modules/cjs/loader.js:853)

When I go down to C:\Users\teste\AppData\Local\my-app\app-1.0.0\resources\app.asar.unpacked\node_modules\@tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node the file is there and perfectly accessible

I'm running windows 10, node v12.13.0, electron 8.2.1 with electron forge

My package.json is:

{
  "name": "my-app",
  "productName": "my-app",
  "version": "1.0.0",
  "description": "My Electron application description",
  "main": "src/index.js",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make",
    "publish": "electron-forge publish",
    "lint": "echo \"No linting configured\"",
    "install": "electron-rebuild --pre-gyp-fix"
  },
  "keywords": [],
  "author": "guzeda",
  "license": "MIT",
  "config": {
    "forge": "./forge.config.js"
  },
  "dependencies": {
    "@electron-forge/plugin-auto-unpack-natives": "^6.0.0-beta.50",
    "@tensorflow/tfjs": "^1.5.1",
    "@tensorflow/tfjs-node": "^1.5.1",
    "electron-reload": "^1.5.0",
    "electron-squirrel-startup": "^1.0.0",
    "face-api.js": "^0.22.2",
    "jquery": "^3.4.1",
    "material-design-lite": "^1.3.0"
  },
  "devDependencies": {
    "@electron-forge/cli": "^6.0.0-beta.50",
    "@electron-forge/maker-deb": "^6.0.0-beta.50",
    "@electron-forge/maker-rpm": "^6.0.0-beta.50",
    "@electron-forge/maker-squirrel": "^6.0.0-beta.50",
    "@electron-forge/maker-zip": "^6.0.0-beta.50",
    "electron": "8.2.1",
    "electron-rebuild": "^1.10.1"
  }
}

My forge.config is:

module.exports = {
    makers: [
        {
            name: '@electron-forge/maker-squirrel',
            config: {
                name: "my-app"
            }
        }
    ],
    plugins: [
        ['@electron-forge/plugin-auto-unpack-natives']
    ],
    packagerConfig:{asar:true}
}

I appreciate any help


Solution

  • I just found out the solution. That happened because the dll needs to be in the same folder as the buddings. The error message was very misleading.

    At the end it was necessary to write some post install script to copy the correct dll to the folder and it worked perfectly