Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaged x64 Angular Electron app produces javascript error: Cannot find module 'electron-edge-js' #138

Closed
tannerb1996 opened this issue Jul 8, 2022 · 11 comments

Comments

@tannerb1996
Copy link

tannerb1996 commented Jul 8, 2022

I'm able to successfully run an Angular project with electron-edge-js in dev; however, when packaging the app using electron-packager, the application fails to load and produces a JS error stating "Cannot find module 'electron-edge-js'". I've followed the edge-js documentation for setup and usage, with the below snippet's being my initialization (NOTE: this initialization is occurring in the electron main process):
const edge = require('electron-edge-js');

These are the dependencies referenced in the root packages.json file:
"electron": "^17.4.9", "electron-edge-js": "^17.0.0", "electron-packager": "^15.5.1",

Can someone please assist with some info on why this dependency may not be included properly on build? For reference, this is the build command for Windows apps that I've been using:
npm run build --prod && cross-var electron-packager dist/my-app $npm_package_name-$npm_package_version --out=packages --platform=win32 --arch=all --overwrite

EDIT FOR MORE INFO:
I'm also running node version 16.13.1, if that makes any sort of difference.

@agracio
Copy link
Owner

agracio commented Jul 27, 2022

Did you check packaging sample and associated issues mentioned in redme?

@dbuldansjah
Copy link

For those who has problem with "The edge module has not been pre-compiled for Electron version 17.4.8" which is using webpack after publishing with electron-builder.
the steps that I resolve this problem are:

npm i electron-edge-js (the latest).
Configure webpack.config.js as such :
externals: {
'electron-edge-js': 'commonjs2 electron-edge-js',
},
Add extraResources as such: extraResources:[
"./node_modules/electron-edge-js/**",
],
on Main.js (electron) call the global:
require("module").globalPaths.push(process.cwd()+'/node_modules');
refer to: [https://github.com/ScottJMarshall/electron-webpack-module-resolution]
then:
var edge = require('electron-edge-js');

@agracio agracio closed this as completed Apr 30, 2024
@AlekseyKurakin
Copy link

@dbuldansjah Hey, just a bit confused. where should we add extraResources? Its not a property in webpack config

@agracio
Copy link
Owner

agracio commented Sep 18, 2024

Take a look at Packaging Electron application in README it has examples for different application packagers including Webpack.

@AlekseyKurakin
Copy link

@agracio yep tried that, seems like now it has to be included by a plugin

plugins: [
  new webpack.LoaderOptionsPlugin({
    options: {
      extraResources:[
        "./node_modules/electron-edge-js/**",
      ]
    }
  })
],

image (9)

btw still didnt work for me. Now it tells that "cannot find module electron-edje-js"

@agracio
Copy link
Owner

agracio commented Sep 18, 2024

What packager are you using, did you try to use externals like in examples?

@AlekseyKurakin
Copy link

Hey sorry for the delay, today i spend about 14hours total looking what i`m doing wrong.

I'm using webpack and was trying to connect to .net dll from my angular+electron.js project.
Everything was fine with running project as direct electron application, but when i tried to build it using electron-forge i start getting strange errors like "cannot find module electro-edje-js".

So i connected webpack config and applied examples from README file and for some reason it didnt work, but then i decided to run electron-edje-js in forked proccess and it worked (same as the example in README file: created a fork from main.js then applied my code in child.js file).

Right now what i can see that module is working but i still cant call for my .net code because of error: "Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.".
I believe that is something with EDGE_APP_ROOT env. Should it point to the directory where .dll and json files stored or directly to ,json file?

@agracio
Copy link
Owner

agracio commented Sep 18, 2024

Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. usually means it is trying to run as .NET Framework instead of .NET Core.
It is probably somehow ignoring process.env.EDGE_USE_CORECLR = 1 or it was not passed properly.

Take a look at electron-forge example added today to README, it does not use webpack but should be an easy addon.

Main points for electron-forge:

  • Exclude electron-edge-js from rebuild
  • Exclude electron-edge-js and edge-cs from asar archive
  • Make sure you have node_modules/electron-edge-js and node_modules/edge-cs in your resources folder.
  • Move .NET binaries to resources folder

I have updated forge.config.js with annotations for each step.

@AlekseyKurakin
Copy link

You are absolutely right. I didnt noticed that i put process.env.EDGE_USE_CORECLR = 1 after edge = require('electron-edge-js') so that was the problem, now it working!
And thank you for electron-forge example it came just in time! My solution seems a bit off, so i will rebuild it

@dbuldansjah
Copy link

dbuldansjah commented Sep 18, 2024 via email

@agracio
Copy link
Owner

agracio commented Sep 18, 2024

There was an issue opened here: agracio/electron-edge-js-quick-start#19 that is the reason for electron-forge example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants