thiagoelg / node-printer

Native node.js printer
125 stars 75 forks source link

Not compiling with electron v20 #56

Open debianw opened 1 year ago

debianw commented 1 year ago

Node: 16.16.0 (lts) OS: MacOS 12.5 @thiagoelg/node-printer: 0.6.2 electron v20.0.3

Electron v19 is OK, but Electron v20 is complaining with this:

⠴ Building module: node-printer, Completed: 0  CXX(target) Release/obj.target/node_printer/src/node_printer_posix.o
⠏ Building module: node-printer, Completed: 0In file included from ../src/node_printer_posix.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:180:
../../../nan/nan_callbacks.h:55:23: error: no member named 'AccessorSignature' in namespace 'v8'
typedef v8::Local<v8::AccessorSignature> Sig;
                  ~~~~^
⠋ Building module: node-printer, Completed: 0In file included from ../src/node_printer_posix.cc:1:
In file included from ../src/node_printer.hpp:4:
In file included from ../src/macros.hh:4:
../../../nan/nan.h:2546:8: error: no matching member function for call to 'SetAccessor'
  tpl->SetAccessor(
  ~~~~~^~~~~~~~~~~
/Users/waly/.electron-gyp/20.0.3/include/node/v8-template.h:814:8: note: candidate function not viable: no known conversion from 'imp::Sig' (aka 'int') to 'v8::SideEffectType' for 7th argument
  void SetAccessor(
       ^
/Users/waly/.electron-gyp/20.0.3/include/node/v8-template.h:807:8: note: candidate function not viable: no known conversion from 'imp::NativeGetter' (aka 'void (*)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value> &)') to 'v8::AccessorGetterCallback' (aka 'void (*)(Local<v8::String>, const PropertyCallbackInfo<v8::Value> &)') for 2nd argument
  void SetAccessor(
       ^
⠼ Building module: node-printer, Completed: 0../src/node_printer_posix.cc:310:5: warning: unused variable 'isolate' [-Wunused-variable]
    MY_NODE_MODULE_HANDLESCOPE;
    ^
../src/macros.hh:12:38: note: expanded from macro 'MY_NODE_MODULE_HANDLESCOPE'
#  define MY_NODE_MODULE_HANDLESCOPE MY_NODE_MODULE_ISOLATE_DECL Nan::HandleScope scope
                                     ^
../src/macros.hh:10:52: note: expanded from macro 'MY_NODE_MODULE_ISOLATE_DECL'
#  define MY_NODE_MODULE_ISOLATE_DECL v8::Isolate* isolate = v8::Isolate::GetCurrent();
                                                   ^
⠴ Building module: node-printer, Completed: 01 warning and 2 errors generated.
⠦ Building module: node-printer, Completed: 0make: *** [Release/obj.target/node_printer/src/node_printer_posix.o] Error 1
✖ Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild '/Users/waly/Development/prototype/test/node_modules/@thiagoelg/node-printer'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".

Error: `make` failed with exit code: 2

Error: node-gyp failed to rebuild '/Users/waly/Development/prototype/test/node_modules/@thiagoelg/node-printer'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".

Error: `make` failed with exit code: 2

    at NodeGyp.rebuildModule (/Users/waly/Development/prototype/test/node_modules/electron-rebuild/lib/src/module-type/node-gyp.js:120:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ModuleRebuilder.rebuildNodeGypModule (/Users/waly/Development/prototype/test/node_modules/electron-rebuild/lib/src/module-rebuilder.js:98:9)
    at async ModuleRebuilder.rebuild (/Users/waly/Development/prototype/test/node_modules/electron-rebuild/lib/src/module-rebuilder.js:128:14)
    at async Rebuilder.rebuildModuleAt (/Users/waly/Development/prototype/test/node_modules/electron-rebuild/lib/src/rebuild.js:149:13)
    at async Rebuilder.rebuild (/Users/waly/Development/prototype/test/node_modules/electron-rebuild/lib/src/rebuild.js:112:17)
    at async /Users/waly/Development/prototype/test/node_modules/electron-rebuild/lib/src/cli.js:158:9
richard-ive-m4 commented 1 year ago

I was having the same issue. It's in the nan package. There's a patch fix in this issue: https://github.com/nodejs/nan/issues/942

Whilst the patch is waiting to be merged you can apply it manually to your local copy in node_modules

thealexbaron commented 1 year ago

Whilst the patch is waiting to be merged you can apply it manually to your local copy in node_modules

✅ can confirm that manually applying this patch will solve the problem

I created a fork of node printer https://github.com/thealexbaron/node-printer and updated the dependencies to use this commit https://github.com/weedz/nan/commit/a679b69b92e1997f6b40f1d3981a58a0021e1b99 and I was able to get node-printer to install with electron-builder 20

greghmerrill commented 1 year ago

I'm trying to use the fork @thealexbaron so graciously provided to address this, but having what looks like a different issue. Hoping someone can tell me where I'm going wrong? I try to install this simple package.json:

{
  "name": "bug",
  "version": "0.0.1",
  "scripts": {
    "preinstall": "npm config set msvs_version=2015",
    "postinstall": "electron-rebuild -f -m node_modules/@thealexbaron/node-printer"
  },
  "keywords": [],
  "dependencies": {
    "@thealexbaron/node-printer": "https://github.com/thealexbaron/node-printer.git",
    "nan": "git+https://github.com/weedz/nan.git"
  },
  "devDependencies": {
    "electron": "20.0.2",
    "electron-rebuild": "3.2.7",
    "node-abi": "3.24.0"
  }
}

But I receive these errors:

C:\views\electron-rebuild-issue\electron-20>npm install
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> bug@0.0.1 preinstall
> npm config set msvs_version=2015

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> bug@0.0.1 postinstall
> electron-rebuild -f -m node_modules/@thealexbaron/node-printer

\ Building module: node-printer, Completed: 0Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
\ Building module: node-printer, Completed: 0cl : Command line warning D9002: ignoring unknown option '/Zc:__cplusplus' [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
  node_printer.cc
| Building module: node-printer, Completed: 0c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-callbacks.h(221): error C2059: syntax error: '' [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-callbacks.h(335): error C2059: syntax error: '' [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-isolate.h(292): error C3646: 'legacy_oom_error_callback': unknown override specifier [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-isolate.h(292): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-isolate.h(1482): error C2061: syntax error: identifier 'LegacyOOMErrorCallback' [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-isolate.h(1545): error C2061: syntax error: identifier 'WasmDynamicTieringEnabledCallback' [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-initialization.h(290): error C2061: syntax error: identifier 'LegacyOOMErrorCallback' [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
c:\users\gmerrill\.electron-gyp\20.0.2\include\node\v8-typed-array.h(28): warning C4309: 'static_cast': truncation of constant value [C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer\build\node_printer.vcxproj]
× Rebuild Failed

An unhandled error occurred inside electron-rebuild
node-gyp failed to rebuild 'C:\views\electron-rebuild-issue\electron-20\node_modules\@thealexbaron\node-printer'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".

Error: `C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1

The errors look different from what others reported, so I wonder if I have some more fundamental issue. Does anyone have a pointer for what I'm doing wrong? Is my MSBuild/msvs_version version too old?

Also note, it works fine for electron 19 ... it only fails when I switch to 20.

greghmerrill commented 1 year ago

Disregard my last comment - I installed VS 2022 with C++ and the following build fine for me. So looks like everything is good.

{
  "name": "bug",
  "version": "0.0.1",
  "scripts": {
    "postinstall": "electron-rebuild -f -m node_modules/@thealexbaron/node-printer"
  },
  "keywords": [],
  "dependencies": {
    "@thealexbaron/node-printer": "https://github.com/thealexbaron/node-printer.git",
    "nan": "git+https://github.com/weedz/nan.git"
  },
  "devDependencies": {
    "electron": "20.0.1",
    "electron-rebuild": "3.2.7",
    "node-abi": "3.24.0"
  }
}

FYI I was also able to build successfully with 21.0.1

{
  "name": "bug",
  "version": "0.0.1",
  "scripts": {
    "postinstall": "electron-rebuild -f -m node_modules/@thealexbaron/node-printer"
  },
  "keywords": [],
  "dependencies": {
    "@thealexbaron/node-printer": "https://github.com/thealexbaron/node-printer.git",
    "nan": "git+https://github.com/weedz/nan.git"
  },
  "devDependencies": {
    "electron": "21.0.1",
    "electron-rebuild": "3.2.7",
    "node-abi": "3.24.0"
  }
}
saileshkush95 commented 1 year ago

@greghmerrill can you please share comple code with electron 20, I'm facing error with electron 20

john8329 commented 10 months ago

To make it work with Electron 20, use the patched version by https://github.com/grandchef/node-printer and change bindings.gyp to use -std=c++17 under xcode_settings. No change was required for windows it seems.

In my case it seems to yield positive results, although it's too early to say.

Also use Python up to v3.9, later versions wreck node-gyp. You can override it with the PYTHON env variable.