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

在electron上运行require ffcreator报错 #348

Closed
wth1107 opened this issue Apr 21, 2023 · 13 comments
Closed

在electron上运行require ffcreator报错 #348

wth1107 opened this issue Apr 21, 2023 · 13 comments

Comments

@wth1107
Copy link

wth1107 commented Apr 21, 2023

electron 24.1.2 node 18.14.0 ffcreator ^7.0.3 运行在win10系统
App threw an error during load
Error: The module '\?\D:\project\electron\ef3\node_modules.store\[email protected]\node_modules\gl\build\Release\webgl.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 108. This version of Node.js requires
NODE_MODULE_VERSION 114. Please try re-compiling or re-installing
the module (for instance, using npm rebuild or npm install).
at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822)
at Module._extensions..node (node:internal/modules/cjs/loader:1326:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822)
at Module.load (node:internal/modules/cjs/loader:1096:32)
at Module._load (node:internal/modules/cjs/loader:937:12)
at f._load (node:electron/js2c/asar_bundle:2:13330)
at Module.require (node:internal/modules/cjs/loader:1120:19)
at require (node:internal/modules/cjs/helpers:103:18)
at bindings (D:\project\electron\ef3\node_modules.store\[email protected]\node_modules\bindings\bindings.js:112:48)
at Object. (D:\project\electron\ef3\node_modules.store\[email protected]\node_modules\gl\src\javascript\native-gl.js:1:40)

尝试了官方的.\node_modules.bin\electron-rebuild.cmd 但仍未解决问题 ,哪位大佬给点建议!!

@drawcall
Copy link
Member

Will provide a full electron demo if I have time

@wth1107
Copy link
Author

wth1107 commented Apr 23, 2023

@drawcall 期待

@vutienhc
Copy link

I got the same error. Please help me. Thank you.

@vutienhc
Copy link

@wth1107 Have you found a solution yet?

@wth1107
Copy link
Author

wth1107 commented May 15, 2023

没有啊,我在等待作者的demo

@wth1107
Copy link
Author

wth1107 commented May 27, 2023

@vutienhc @linqian02 好大哥们 有招了吗

@wangmode
Copy link

wangmode commented Jun 9, 2023

@drawcall electron demo 这个有空搞下吧🙇‍

@zjqiudan
Copy link

求demo,等了快1年了....

@wth1107
Copy link
Author

wth1107 commented Sep 11, 2023

半年了。。。o(╥﹏╥)o

@ahnuchen
Copy link

@drawcall 大哥,有招了吗

@drawcall
Copy link
Member

先使用这个项目 #435 ,ffcreator结合electron我后面会更新

@2284730142
Copy link

2284730142 commented Jul 23, 2024

基本上是因为inkpaint的底层用了headless-gl和node-canvas,这两块如果能用electron自带内容编译的话,就没有问题了,但是问题关键就是这两个东西,node-canvas强制切换到3.0-alpha能够正常编译通过(已经支持了node-addon-api),且能够使用,但是headless,使用较新的electron-rebuild,无法编译通过,因为它只支持nan(详情参考node-canvas和headless-gl的binding.gyp文件配置),这两块配置我不太懂,如果有懂的大佬,可以尝试调整这两个东西,来让编译能够通过,如果测试结果ok,希望能共享这个headless-gl的binding.gyp配置

已存在的提问:stackgl/headless-gl#291

@tnfe tnfe deleted a comment from xeoshow Sep 9, 2024
@msudomoikin
Copy link

msudomoikin commented Nov 7, 2024

Hey everyone.

I also was struggling with native modules (node-canvas, headless-gl), couldn't rebuild them for electron runtime. So I've ended with this solution.

I've copied my app code, node_modules and node.exe (version that I used to develop, native modules were built against it) to an electron resources folder, and then in electron I run my app with that standalone node binary.

Project structure is

/backend
  node_modules
  src/app.js
/electron
  main.js
/node
  node.exe

backend folder is where my node app with ffcreator
electron is electron project :)
node is folder with unpacked windows binaries. same version with which I developed and installed packages in backend folder.

Here's package.json for electron, notice --extraResource parameters in package script to copy my app and node binary

{
  "name": "myElectronApp",
  "version": "1.0.0",
  "main": "main.js",
  "type": "module",
  "scripts": {
    "start": "electron .",
    "package": "electron-packager . --overwrite --platform=win32 --arch=x64 --prune=true --out=dist  --extraResource='../backend' --extraResource='../node/node.exe'" 
  },
  "author": "Matvey Sudomoykin [email protected]",
  "devDependencies": {
    "electron": "^33.1.0",
    "electron-packager": "^17.1.2"
  }
}

Then I can run my app from electron like so

//electron/main.js

const node = path.join(process.resourcesPath, "node.exe"); //path to copied node binary
const nodeModulesBackend = path.join(process.resourcesPath, "backend", "node_modules"); //path to copied node_modules
const app = [path.join(process.resourcesPath, "backend", "src", "app.js")] //path to my app entry file

//command to run my app with copied node binary
backendProcess = spawn(
    node,
    app,
    {
      env: { ...process.env, NODE_PATH: nodeModulesBackend },
      cwd: path.join(process.resourcesPath, "backend"),
    }
  );

I can communicate between electron and my app with ipcMain and ipcRenderer (show if app has started, display console output and such). To package everything I'm using electron-packager, same solution can be done with electron-builder if you need installer.

I'ts not very elegant solution, but it works. I can ship my code to a customer as a portable desktop app, without needing them to install node. Also they get nice GUI to run and control app, without terminal screens, bat-files or other ugly things.

Hope this helps someone!

@wth1107 wth1107 closed this as completed Nov 15, 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