PeculiarVentures / graphene

A simple layer for interacting with PKCS #11 / PKCS11 / CryptoKI for Node in TypeScript. (Keywords: Javascript, PKCS#11, Crypto, Smart Card, HSM)
MIT License
169 stars 34 forks source link

`npm i` failing on Node 20 on Mac OSX #157

Open mrhornsby opened 10 months ago

mrhornsby commented 10 months ago

Hi,

Thanks for the great project, I've been using it for a number of years.

I recently ran in to a problem when upgrading to Node.js 20. On running npm i on a dependent project it fails to to install graphene-pk11-2.3.2 due to a handful of node-gyp errors (these appear to be coming from the pkcs11js dependency, so maybe I should raise the query on that project of yours instead?):

npm ERR! /Users/mark/Library/Caches/node-gyp/20.11.0/include/node/v8-maybe.h:123:67: error: expected '(' for function-style cast or type construction
npm ERR! template <class T, std::enable_if_t<!std::is_lvalue_reference_v<T>>* = nullptr>
npm ERR! /Users/mark/Library/Caches/node-gyp/20.11.0/include/node/v8-maybe.h:106:69: error: expected '(' for function-style cast or type construction
npm ERR!   template <class U, std::enable_if_t<!std::is_lvalue_reference_v<U>>*>
npm ERR!                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
npm ERR! /Users/mark/Library/Caches/node-gyp/20.11.0/include/node/v8-maybe.h:123:43: error: no template named 'is_lvalue_reference_v' in namespace 'std'; did you mean 'is_lvalue_reference'?
npm ERR! template <class T, std::enable_if_t<!std::is_lvalue_reference_v<T>>* = nullptr>
npm ERR! /Users/mark/Library/Caches/node-gyp/20.11.0/include/node/v8-maybe.h:106:45: error: no template named 'is_lvalue_reference_v' in namespace 'std'; did you mean 'is_lvalue_reference'?
npm ERR!   template <class U, std::enable_if_t<!std::is_lvalue_reference_v<U>>*>

After a bit of poking around I determined that is_lvalue_reference_v appears to be a C++17 feature which is just a call to is_lvalue_reference and then ::value on the result so I hacked my local cache of v8 headers and everything works as expected i.e. change:

template <class U, std::enable_if_t<!std::is_lvalue_reference_v<U>>*>

to:

template <class U, std::enable_if_t<!std::is_lvalue_reference<U>::value>*>

and:

template <class T, std::enable_if_t<!std::is_lvalue_reference_v<T>>* = nullptr>

to:

template <class T, std::enable_if_t<!std::is_lvalue_reference<T>::value>* = nullptr>

in /Users/mark/Library/Caches/node-gyp/20.11.0/include/node/v8-maybe.h.

Afraid this isn't my area of expertise, but I'm guessing that you might be able to pass the C++17 flags in to node-gyp to avoid having to make these changes to the v8 headers?

For reference I'm using:

Mac OSX 14.2.1 Node.js 20.11.0 (through Homebrew) node-gyp@10.0.1 Apple clang version 15.0.0 (clang-1500.1.0.2.5)

Thanks

Mark