electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.42k stars 507 forks source link

can't load node-printer native module #3322

Open sibelius opened 1 year ago

sibelius commented 1 year ago

Pre-flight checklist

Electron Forge version

6.4.1

Electron version

26.1.0

Operating system

mac os x ventura, m1, arm64

Last known working Electron Forge version

No response

Expected behavior

it should work well with node-printer native module

We are using this package https://github.com/grandchef/node-printer/issues/4

the native module works well on node, but it does not work well on electron

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies: 1 / 1 [0.6s]
✔ Running generateAssets hook
✔ [plugin-webpack] Compiling main process code [1s]
✔ [plugin-webpack] Launching dev servers for renderer process code [0.6s]
› Output Available: http://localhost:9000

  App threw an error during load
Error: Module did not self-register: '/app/node_modules/@grandchef/node-printer/lib/binding/node_printer.node'.
  at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822)
at Object.<anonymous> (node:internal/modules/cjs/loader:1356:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at node:internal/modules/cjs/loader:967:12
at Function._load (node:electron/js2c/asar_bundle:2:13330)
at Module.require (node:internal/modules/cjs/loader:1150:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/app/node_modules/@grandchef/node-printer/lib/printer-binding.js:4:17)
  at Module._compile (node:internal/modules/cjs/loader:1271:14)

Actual behavior

it should work well with node-printer native module

We are using this package https://github.com/grandchef/node-printer/issues/4

the native module works well on node, but it does not work well on electron

✔ Checking your system
✔ Locating application
✔ Loading configuration
✔ Preparing native dependencies: 1 / 1 [0.6s]
✔ Running generateAssets hook
✔ [plugin-webpack] Compiling main process code [1s]
✔ [plugin-webpack] Launching dev servers for renderer process code [0.6s]
› Output Available: http://localhost:9000

  App threw an error during load
Error: Module did not self-register: '/app/node_modules/@grandchef/node-printer/lib/binding/node_printer.node'.
  at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822)
at Object.<anonymous> (node:internal/modules/cjs/loader:1356:18)
at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822)
at Module.load (node:internal/modules/cjs/loader:1126:32)
at node:internal/modules/cjs/loader:967:12
at Function._load (node:electron/js2c/asar_bundle:2:13330)
at Module.require (node:internal/modules/cjs/loader:1150:19)
at require (node:internal/modules/cjs/helpers:110:18)
at Object.<anonymous> (/app/node_modules/@grandchef/node-printer/lib/printer-binding.js:4:17)
  at Module._compile (node:internal/modules/cjs/loader:1271:14)

Steps to reproduce

yarn add @grandchef/node-printer

try to import and use @grandchef/node-printer on main process

Additional information

I've tried to put this package as an external dep

externals: {
    'usb': 'usb',
    '@grandchef/node-printer': '@grandchef/node-printer',
  },

similar to usb package

sibelius commented 1 year ago

rebuild gives me this error

.electron-gyp/26.1.0/include/node/v8-maybe.h:123:67: error: expected '(' for function-style cast or type construction
template <class T, std::enable_if_t<!std::is_lvalue_reference_v<T>>* = nullptr>
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
In file included from ../src/node_printer.cc:1:
In file included from ../src/node_printer.hpp:4:
In file included from ../src/macros.hh:4:
In file included from ../../../nan/nan.h:60:

using electron-rebuild

sibelius commented 1 year ago

repro https://github.com/sibelius/electron-printer