I'm trying to install node-ffi as a package in one of my electron applications. doing a straight " npm install node-ffi" failed... so I ended up trying the "Source Install" section found here:

  https://github.com/node-ffi/node-ffi

What I've Done So Far:

  npm install --global windows-build-tools

This created the following folder:

PS C:\Users\jmk\.windows-build-tools> dir
Directory: C:\Users\jmk\.windows-build-tools


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2020-09-23  10:15 AM                python27
-a----        2020-09-23  10:15 AM       20246528 python-2.7.15.amd64.msi
-a----        2020-09-23  11:06 AM          51992 python-log.txt
-a----        2020-09-23  10:15 AM        1119848 vs_BuildTools.exe

As yo u can see it installed python2 but I changed the default python that node-gyp uses like so:

PS C:\Users\jmk\source\github\node-ffi> npm config set python C:\Python38\python.exe

And then confirmed like so:

nPS C:\Users\jmk\source\github\node-ffi> node-gyp configure
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp info find Python using Python version 3.8.5 found at "C:\Python38\python.exe"
gyp info find VS using VS2019 (16.7.30503.244) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python38\python.exe
gyp info spawn args [
gyp info spawn args   'C:\\Users\\jmk\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\jmk\\source\\github\\node-ffi\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\jmk\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\jmk\\AppData\\Local\\node-gyp\\Cache\\12.18.4\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\jmk\\AppData\\Local\\node-gyp\\Cache\\12.18.4',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\jmk\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\jmk\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\12.18.4\\\\<(target_arch)\\\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\jmk\\source\\github\\node-ffi',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Users\\jmk\\source\\github\\node-ffi\\build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info ok
PS C:\Users\jmk\source\github\node-ffi>

now when i do a "node-gyp build" or rebuild, i see errors like:

C:\Users\jmk\source\github\node-ffi\src\ffi.cc(49,57): error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\AppData\Local\node-gyp\Cache\12.18.4\include\node\v8.h(6126,46): message : see declaration of 'v8::FunctionTemplate::GetFunction' (compiling source file ..\src\ffi.cc) [C:\Users\jmk\source\github\node-ffi\build\ffi_bin 
dings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(48,8): error C2661: 'Nan::Set': no overloaded function takes 2 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(51,60): error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\AppData\Local\node-gyp\Cache\12.18.4\include\node\v8.h(6126,46): message : see declaration of 'v8::FunctionTemplate::GetFunction' (compiling source file ..\src\ffi.cc) [C:\Users\jmk\source\github\node-ffi\build\ffi_bin 
dings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(50,8): error C2661: 'Nan::Set': no overloaded function takes 2 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(53,54): error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\AppData\Local\node-gyp\Cache\12.18.4\include\node\v8.h(6126,46): message : see declaration of 'v8::FunctionTemplate::GetFunction' (compiling source file ..\src\ffi.cc) [C:\Users\jmk\source\github\node-ffi\build\ffi_bin 
dings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(52,8): error C2661: 'Nan::Set': no overloaded function takes 2 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(55,59): error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]
C:\Users\jmk\AppData\Local\node-gyp\Cache\12.18.4\include\node\v8.h(6126,46): message : see declaration of 'v8::FunctionTemplate::GetFunction' (compiling source file ..\src\ffi.cc) [C:\Users\jmk\source\github\node-ffi\build\ffi_bin
dings.vcxproj]
C:\Users\jmk\source\github\node-ffi\src\ffi.cc(54,8): error C2661: 'Nan::Set': no overloaded function takes 2 arguments [C:\Users\jmk\source\github\node-ffi\build\ffi_bindings.vcxproj]

I tried to track down the first error. This is what ffi.cc(49,57) looks like:

Nan::New<FunctionTemplate>(FFIPrepCif)->GetFunction());

And this is what C:\Users\jmk\AppData\Local\node-gyp\Cache\12.18.4\include\node\v8.h(6126,46) looks like

  /** Returns the unique function instance in the current execution context.*/
  V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
      Local<Context> context);

So it seems the new version of v8 requires that GetFunction be passed a context? not sure. I'm not JS programmer nor C++ programmer. I thought if it was something simple, like installing some new library?

https://github.com/node-ffi/node-ffi/tree/master/src is the code I'm essentially dealing with at this point.

Can you point me in the right direction please?

thanks.

1

There are 1 best solutions below

0
On

Node-ffi is no longer maintained and doesn't work with Node versions > 10, use node-ffi-napi instead. There are a number of related packages that are also no longer maintained and have napi functioning forks (e.g. ref-napi, ref-wchar-napi).

The old packages and the napi forks have the same API as far as I can tell, so you just need to install the new versions and change the imports in your code and it should install and run.