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

Run from electron #30

Closed
Apidcloud opened this issue Jan 29, 2018 · 13 comments
Closed

Run from electron #30

Apidcloud opened this issue Jan 29, 2018 · 13 comments

Comments

@Apidcloud
Copy link

Apidcloud commented Jan 29, 2018

Good evening!

I wonder if it's possible to use this package from within electron?

I'm using electron 1.7.11 and canvas-prebuilt 1.6.5-prerelease.1, but when I attempt to do so, the following error is raised:

Uncaught Error: A dynamic link library (DLL) initialization routine failed.
\\?\D:\Workspace\GitHub\_Scarlett\scarlett-editor\node_modules\canvas-prebuilt\canvas\build\Release\canvas.node
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Workspace\GitHub\_Scarlett\scarlett-editor\node_modules\canvas-prebuilt\canvas\lib\bindings.js:3:18)
    at Object.<anonymous> (D:\Workspace\GitHub\_Scarlett\scarlett-editor\node_modules\canvas-prebuilt\canvas\lib\bindings.js:5:3)

The output yielded from windows.process.version is v7.9.0.

Any ideas on how to build this package targeting electron?
I've read something about electron-rebuild. Could it be used somehow?

Thanks!

@chearon
Copy link
Member

chearon commented Jan 29, 2018

It could be that Electron loads a DLL that canvas-prebuilt does as well (e.g. libz2-1.dll) and they're conflicting.

The best way to know that is get Dependency Walker and point it at the Electron executable, then see if it or any of its dependencies are the same name as any of the ones in node_modules/canvas-prebuilt/build/Release.

Hard for me to say much more than that as the error doesn't give us much detail and I don't have Windows anymore, but that's my best guess.

@Apidcloud
Copy link
Author

Apidcloud commented Jan 29, 2018

From what I've been reading online, I think it might be due to the fact electron (v1.7.11) uses a specific version of node within (7.9), whereas I have 8.9.4 installed.
Is there a way to build is specifically for that version instead?

Thanks!

@chearon
Copy link
Member

chearon commented Jan 29, 2018

Oh, if you're right that isn't too hard, there's a --target option. Just do npm install --target 7.9 canvas-prebuilt

@Apidcloud
Copy link
Author

I'll give that a go once I have the chance then!

@Apidcloud
Copy link
Author

Apidcloud commented Jan 30, 2018

Hmm no luck with node 7.9 and npm 4.2:

npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--target" "7.9" "canvas-prebuilt"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0

npm ERR! Cannot convert undefined or null to object

Probably because that version of npm doesn't support the flag. Tried with node 8.9.4 and npm 5.4, and got the following error:

npm ERR! No valid versions available for 7.9

I think it has to do with the npm registry, meaning it can't find the package targeting 7.9?

I can install it with no problems without the flag.

@chearon
Copy link
Member

chearon commented Jan 30, 2018

Looks like you actually need a = and the 4 digit number:

$ npm install canvas-prebuilt --target=7.9.0

@Apidcloud
Copy link
Author

Apidcloud commented Jan 30, 2018

That did it, but still no luck within electron 😢

Can we try this? (the manual rebuild for electron 1.7.11, specifically)
https://github.com/electron/electron/blob/master/docs/tutorial/using-native-node-modules.md

I'll give it a try as well.

@Apidcloud
Copy link
Author

Was able to use node-gyp rebuild --target=1.7.11 --arch=x64 --dist-url=https://atom.io/download/electron with no errors! I'll keep going.

Edit:
It seems to work!!! 💯 Could you please release a version targeting electron 1.7.11 then? The one I'm using (through msdf-bmfont-xml - see related issue soimy/msdf-bmfont-xml#18) is 1.6.5-prerelease.1

@tommypreger
Copy link

I'm also trying to run this from Electron without luck. I'm using the latest alpha (I need registerFont).

This is the error:

Uncaught Error: The module 'node_modules/canvas-prebuilt/canvas/build/Release/canvas.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 54.

@Apidcloud
Copy link
Author

@chearon From my understanding, I'm basically rebuilding node-canvas with a specific electron version in mind, correct? Can you tell how to create a prebuilt version that I can publish and use as a dependency? For now I have been doing it locally, linking projects, but I would like to automate it if possible.

Or does the new version allow me to set some flags in that regard?

Thank you!

@tettusud
Copy link

any luck with this issue? I am still facing the issue. I use node v10 , electron 3 and canvas. I get the same DLL issue

@das-solo
Copy link

das-solo commented Feb 6, 2019

@Apidcloud I have also come across this issue. How did you do it locally by linking projects? I have also tried building it by using node-gyp and electron-rebuild with zero success?

@Apidcloud
Copy link
Author

Apidcloud commented Feb 6, 2019 via email

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

5 participants