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

I use electron v6.1.5 and node.js v12.4.0 and electron-edge-js have a problem about Cannot find module edge_nativeclr #74

Closed
david1025 opened this issue Dec 25, 2019 · 10 comments

Comments

@david1025
Copy link

Electron v6.1.5
Node v12.4.0
vue/cli 4.0.5
electron-edge-js v12.8.1
windows 10 x64.
The error occurs when I require the electron-edge-js module.
var edge = require('electron-edge-js');

Uncaught Error: Cannot find module 'D:\workspace\ws_workspace\electron-vue-scaffold\node_modules\electron\dist\resources\electron.asar\renderer\native\win32\x64\12.4.0\edge_nativeclr' at webpackEmptyContext (eval at ./node_modules/electron-edge-js/lib sync recursive (app.js:1002), <anonymous>:2:10) at eval (edge.js?3e21:62) at Object../node_modules/electron-edge-js/lib/edge.js (chunk-vendors.js:7494) at __webpack_require__ (app.js:791) at fn (app.js:151) at eval (index.js:6) at Module../src/dll/index.js (app.js:1143) at __webpack_require__ (app.js:791) at fn (app.js:151) at eval (main.js:17)

@gdavidkov
Copy link
Contributor

You shouldn't pack the native modules.

@tritrancs
Copy link

You shouldn't pack the native modules.

Can you be more specific on how to make it work? I got same issue, searched around, can see other get same issue but could not find a solution.
Thanks

@agracio
Copy link
Owner

agracio commented Jan 8, 2020

Take a look at #39

@tritrancs
Copy link

I have made some progress and would like to share for those facing the same issue.
I am using Vue CLI 4 and electron-builder. I believe this is an issue with either of these.
First, when I changed to call electron edge js from the main process and try to run the app in development, I got an error as below
image
We can see that the path is absolutely wrong. The correct path in all cases should be '[Application folder]\node_modules\electron-edge-js\lib\native\win32\x64\12.4.0\edge_nativeclr' (I downloaded the quick start and the path is correct in that project).
I then tried to change the path in edge.js file, run the app again, still fail even the path is now correct.
After days of research, I found an issue in electron builder: nklayman/vue-cli-plugin-electron-builder#334
I tried to apply to the edge.js file in electron-edge-js. I replaced 2 lines
edge = require(edgeNative);
to
edge = non_webpack_require(edgeNative);
and
compiler = require(compilerName);
to
compiler = non_webpack_require(compilerName);
then it works.
So it's webpack in Vue CLI/electron-builder that caused it.
The issue is that I changed the source of the edge module locally, I don't know how to include these changes so that the build servers can understand it.

@Ricardo1601
Copy link

Ricardo1601 commented Feb 10, 2020

I have made some progress and would like to share for those facing the same issue.
I am using Vue CLI 4 and electron-builder. I believe this is an issue with either of these.
First, when I changed to call electron edge js from the main process and try to run the app in development, I got an error as below
image
We can see that the path is absolutely wrong. The correct path in all cases should be '[Application folder]\node_modules\electron-edge-js\lib\native\win32\x64\12.4.0\edge_nativeclr' (I downloaded the quick start and the path is correct in that project).
I then tried to change the path in edge.js file, run the app again, still fail even the path is now correct.
After days of research, I found an issue in electron builder: nklayman/vue-cli-plugin-electron-builder#334
I tried to apply to the edge.js file in electron-edge-js. I replaced 2 lines
edge = require(edgeNative);
to
edge = non_webpack_require(edgeNative);
and
compiler = require(compilerName);
to
compiler = non_webpack_require(compilerName);
then it works.
So it's webpack in Vue CLI/electron-builder that caused it.
The issue is that I changed the source of the edge module locally, I don't know how to include these changes so that the build servers can understand it.

Hello, thank you very much for your answer, it was very helpful to me
I modify the vue.config.js to make the path is correct
pluginOptions: {
electronBuilder: {
externals:["electron-edge-js"]
}
But when I use non_webpack_require,, I got an error as below

ReferenceError: non_webpack_require is not defined

Can you be more specific on how to make it work?Thanks!

@tritrancs
Copy link

I have made some progress and would like to share for those facing the same issue.
I am using Vue CLI 4 and electron-builder. I believe this is an issue with either of these.
First, when I changed to call electron edge js from the main process and try to run the app in development, I got an error as below
image
We can see that the path is absolutely wrong. The correct path in all cases should be '[Application folder]\node_modules\electron-edge-js\lib\native\win32\x64\12.4.0\edge_nativeclr' (I downloaded the quick start and the path is correct in that project).
I then tried to change the path in edge.js file, run the app again, still fail even the path is now correct.
After days of research, I found an issue in electron builder: nklayman/vue-cli-plugin-electron-builder#334
I tried to apply to the edge.js file in electron-edge-js. I replaced 2 lines
edge = require(edgeNative);
to
edge = non_webpack_require(edgeNative);
and
compiler = require(compilerName);
to
compiler = non_webpack_require(compilerName);
then it works.
So it's webpack in Vue CLI/electron-builder that caused it.
The issue is that I changed the source of the edge module locally, I don't know how to include these changes so that the build servers can understand it.

Hello, thank you very much for your answer, it was very helpful to me
I modify the vue.config.js to make the path is correct
pluginOptions: {
electronBuilder: {
externals:["electron-edge-js"]
}
But when I use non_webpack_require,, I got an error as below

ReferenceError: non_webpack_require is not defined

Can you be more specific on how to make it work?Thanks!

Sorry, for some reasons the text is trimmed. It should be __non_webpack_require__(edgeNative)

@aliharakeh
Copy link

aliharakeh commented Jan 3, 2021

I'll share my case in case anyone is a beginner like me.

I have this electron-angular app and it seems that you can't use node modules related to the system or electron inside angular (like fs, remote, ..etc), and this was what got me this error as electron would unpack it into asra.unpack by itself and there was no problem in that.

So, you CAN'T do this inside angular project

const fs = require('fs');
const edge = require('electron-edgs-js');
const remote = require('electron').remote

You need to install ngx-electron and use their Electron service.
Example of an angular service code:

import { ElectronService } from 'ngx-electron'

constructor(private _electronService: ElectronService) {
    this.edge = this._electronService.remote.require('electron-edge-js');
    this.path = this._electronService.remote.require('path');
    this.app = this._electronService.remote.app;
  }

  // root Edge folder that contains the .net code and some extra dlls
  getEdgePath(file) {
     return this.path.join(this.app.getAppPath(), 'Edge', file);
   }

  edgeFunc() {
      let _edgeFunc = this.edge.func({
        source:  this.getEdgePath('edge.cs') ,
        references: [
          this.getEdgePath('extra.dll'), // extra dll
          'System.Collections.dll'
        ]
      })
     _edgeFunc('', (err, res) => { ... })
  }

Notes:

  • Some other workaround might be to use window.require(<module>) , I think I saw it somewhere, but I'm not so sure about it.
  • This might also apply for other frameworks like Vue, but I haven't tested it

Conclusion: You just need to find a way to connect to electron's main process from inside the framework correctly

@wallace921029
Copy link

I have made some progress and would like to share for those facing the same issue.
I am using Vue CLI 4 and electron-builder. I believe this is an issue with either of these.
First, when I changed to call electron edge js from the main process and try to run the app in development, I got an error as below
image
We can see that the path is absolutely wrong. The correct path in all cases should be '[Application folder]\node_modules\electron-edge-js\lib\native\win32\x64\12.4.0\edge_nativeclr' (I downloaded the quick start and the path is correct in that project).
I then tried to change the path in edge.js file, run the app again, still fail even the path is now correct.
After days of research, I found an issue in electron builder: nklayman/vue-cli-plugin-electron-builder#334
I tried to apply to the edge.js file in electron-edge-js. I replaced 2 lines
edge = require(edgeNative);
to
edge = non_webpack_require(edgeNative);
and
compiler = require(compilerName);
to
compiler = non_webpack_require(compilerName);
then it works.
So it's webpack in Vue CLI/electron-builder that caused it.
The issue is that I changed the source of the edge module locally, I don't know how to include these changes so that the build servers can understand it.

Hello, thank you very much for your answer, it was very helpful to me
I modify the vue.config.js to make the path is correct
pluginOptions: {
electronBuilder: {
externals:["electron-edge-js"]
}
But when I use non_webpack_require,, I got an error as below

ReferenceError: non_webpack_require is not defined

Can you be more specific on how to make it work?Thanks!

// vue.config.js
module.export = {
    pluginOptions: {
        electronBuilder: {
        externals:["electron-edge-js"]
    }
}

Thanks :).
It works for me.

@1008611
Copy link

1008611 commented Mar 1, 2024

Win10, no problem.
error in Win7.
installed NET Framework 4.6.2, problem resolved.
#39

@agracio
Copy link
Owner

agracio commented Jun 7, 2024

Packaging instructions added to README, all issues should be resolved.

@agracio agracio closed this as completed Jun 7, 2024
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

8 participants