tojocky / node-printer

Native node.js printer
1.53k stars 441 forks source link

Cannot import node-printer in electron 7 app #274

Open plumbn opened 4 years ago

plumbn commented 4 years ago

I'm attempting to use node-printer in an electron 7.1.3 app. As per the docs, I've tried installing the library using npm install printer --runtime=electron --target=7.1.3 --target_arch=x64. It appears to install successfully but when I try to import it in main.js, I get the following error:

App threw an error during load
Error: /home/nate/project-name/node_modules/printer/lib/node_printer.node: invalid ELF header
    at process.func (electron/js2c/asar.js:140:31)
    at process.func [as dlopen] (electron/js2c/asar.js:140:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:922:18)
    at Object.func (electron/js2c/asar.js:140:31)
    at Object.func [as .node] (electron/js2c/asar.js:140:31)
    at Module.load (internal/modules/cjs/loader.js:735:32)
    at Module._load (internal/modules/cjs/loader.js:648:12)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Module.require (internal/modules/cjs/loader.js:775:19)
A JavaScript error occurred in the main process
Uncaught Exception:
Error: /home/nate/project-name/node_modules/printer/lib/node_printer.node: invalid ELF header
    at process.func (electron/js2c/asar.js:140:31)
    at process.func [as dlopen] (electron/js2c/asar.js:140:31)
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:922:18)
    at Object.func (electron/js2c/asar.js:140:31)
    at Object.func [as .node] (electron/js2c/asar.js:140:31)
    at Module.load (internal/modules/cjs/loader.js:735:32)
    at Module._load (internal/modules/cjs/loader.js:648:12)
    at Module._load (electron/js2c/asar.js:717:26)
    at Function.Module._load (electron/js2c/asar.js:717:26)
    at Module.require (internal/modules/cjs/loader.js:775:19)

Since I'm getting an ELF header error, I wonder if I'm just importing it incorrectly. I'm using const printer = require('printer');. I also tried building after install as described in the docs and I tried using electron-rebuild. Both failed to build. Obviously that's not reassuring, but before diving down the rabbit hole of what's going on there, I thought I'd rule out the simple issue first. Any idea what might be going on?

grahamnordstrom commented 4 years ago

@plumbn See this fork https://github.com/thiagoelg/node-printer

shyaminayesh commented 4 years ago

@grahamnordstrom @thiagoelg/node-printer works without any issues for me, can you please direct me why this is happening on @tojocky/node-printer ?

grahamnordstrom commented 4 years ago

@grahamnordstrom @thiagoelg/node-printer works without any issues for me, can you please direct me why this is happening on @tojocky/node-printer ?

Honestly no idea. I just found that the forked project from thiagoelg works.

NelsonFrancisco commented 4 years ago

Same happens to me in node v10.11.0 in Mint 19.1 https://github.com/tojocky/node-printer/issues/274#issuecomment-566820292 solved it though