forge icon indicating copy to clipboard operation
forge copied to clipboard

Error when running project after installing opencv4nodejs

Open stoefln opened this issue 7 years ago • 2 comments

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project follows, as appropriate.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Please describe your issue: When adding opencv4nodejs to my fresh forge installation (webpack template), I am getting following error on start:

✔ Checking your system
✔ Locating Application
✔ Preparing native dependencies: 1 / 1
✔ Compiling Main Process Code
✔ Launch Dev Servers
✔ Compiling Preload Scripts
✔ Launching Application

An unhandled rejection has occurred inside Forge:
TypeError: Cannot set property 'native_modules/opencv/build/lib/libopencv_plot.3.4.dylib' of undefined
    at Promise.all.files.map (/Users/steph/Documents/workspace/electron-opencv-test/node_modules/@marshallofsound/webpack-asset-relocator-loader/dist/index.js:14689:98)

Electron Forge was terminated. Location:
{}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `electron-forge start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

What command line arguments are you passing? npm start

What does your config.forge data in package.json look like?

"config": {
    "forge": {
      "packagerConfig": {},
      "makers": [
        {
          "name": "@electron-forge/maker-squirrel",
          "config": {
            "name": "electron_opencv_test"
          }
        },
        {
          "name": "@electron-forge/maker-zip",
          "platforms": [
            "darwin"
          ]
        },
        {
          "name": "@electron-forge/maker-deb",
          "config": {}
        },
        {
          "name": "@electron-forge/maker-rpm",
          "config": {}
        }
      ],
      "plugins": [
        [
          "@electron-forge/plugin-webpack",
          {
            "mainConfig": "./webpack.main.config.js",
            "renderer": {
              "config": "./webpack.renderer.config.js",
              "entryPoints": [
                {
                  "html": "./src/index.html",
                  "js": "./src/renderer.js",
                  "name": "main_window"
                }
              ]
            }
          }
        ]
      ]
    }
  },

Here is the repo: https://github.com/stoefln/electron-opencv-test

stoefln avatar Jun 08 '19 09:06 stoefln

We took a look at the code in opencv4nodejs and it seems that there's some weird code in there trying to detect Electron + Webpack:

https://github.com/justadudewhohacks/opencv4nodejs/blob/5d02be9b541c29b7e78061e8e5d82772f2f422cf/lib/opencv4nodejs.js#L4-L11

If that special case gets removed, it'll probably "just work".

Closing since it's very unlikely to be specifically an Electron Forge bug.

malept avatar Jun 14 '19 16:06 malept

@malept I have created a small sample app showing the problem.

https://github.com/gallagherrchris/opencv4nodejs-electron-test

I added in some code to force the logic you highlighted above (should return true and force the first code path). https://github.com/gallagherrchris/opencv4nodejs-electron-test/blob/master/src/main.js#L12-L21

I am still having the issue with the module not being found and it hasn't "just work"™

gallagherrchris avatar Aug 22 '19 19:08 gallagherrchris