edge-js build failing with nw-gyp

382 Views Asked by At

Description

I want to use edge-js with nw.js. And as edge-js is not pure js package , I have to rebuild it with nw-gyp to get it working. (https://github.com/nwjs/nw.js/wiki/using-node-modules)

Tried to re-build edge-js with nw-gyp, but facing compilation issues. The error snapshot is attached

Followed below 2 links to install nw-gyp https://github.com/nwjs/nw-gyp#installation

Build edge-js with nw https://github.com/nwjs/nw.js/wiki/Build-native-modules-with-nw-gyp

Package version

"edge-js": "^15.5.2"

Commands used to build

nw-gyp configure --target=0.42.3

nw-gyp rebuild --target=0.42.3

nw.js v0.42.3

Error Message & Stack Trace

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h(16): error : invalid preprocessing directive [E:\compile_node_modules\node_modules\edge-js\build\edge_nati veclr.vcxproj]

In file included from ..\src\dotnet\utils.cpp:1:

In file included from ..\src\dotnet/edge.h:22:

In file included from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h:17:

In file included from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\gcroot.h:42:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\msclr/gcroot.h(58): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj] In file included from ..\src\dotnet\utils.cpp:1:

In file included from ..\src\dotnet/edge.h:22:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h(29): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h(30): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h(31): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h(32): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\vcclr.h(44): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

In file included from ..\src\dotnet\utils.cpp:1:

..\src\dotnet/edge.h(24): error : invalid preprocessing directive [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

..\src\dotnet/edge.h(25): error : invalid preprocessing directive [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

..\src\dotnet/edge.h(27): error : use of undeclared identifier 'System' [E:\compile_node_modules\node_modules\edge-js\build\edge_nativeclr.vcxproj]

Relevant Information

Environment: Windows_NT 10.0.19041 npm configurations


\edge-js> npm config get
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.13.4 node/v12.14.1 win32 x64"

; userconfig C:\Users\<user>\.npmrc
msvs_version = "2015"
node_gyp = "C:\\Users\\<user>\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js"
python = "python2.7"

; globalconfig C:\Users\<user>\AppData\Roaming\npm\etc\npmrc
node_gyp = "C:\\Users\\<user>\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js"

; builtin config undefined
prefix = "C:\\Users\\<user>\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = E:\compile_node_modules\node_modules\edge-js
; HOME = C:\Users\<user>
; "npm config ls -l" to show all defaults.
1

There are 1 best solutions below

0
On

It may be related to Python 3. Node-gyp was originally based on Python 2. It has been transitioning to Python 3 for the past few years.

* 2019 - Node-gyp 5.x started adopting Python 3
* 2020 - Node-gyp 6.x started to work with Python 3
* 2020 - Node-gyp 7.x works with Python 3
* 2021 - Node-gyp 8.x removes all Python 2 support, only supports Python 3

NW-gyp was based on Node-gyp with some tweaks, back when it was using Python 2. It has not been updated to support Python 3. So if you are using newer versions of NW.js, that come with newer versions of Node, and you have newer versions of npm globally installed, it may be trying to use Python 3 stuff with Node-gyp, which doesn't support that. This is all a guess on my part, I know very little about Node-gyp/NW-gyp/Python.

If this hunch is correct then you could try using an older version of NW.js. Node-gyp 5 started Python 3 adoption on 2019-06-13, so the latest node/npm before that would be Node 12.4.0 (2019-06-04) and npm 6.9.0. The version of NW.js that ships with Node 12.4.0 is v0.39.2.

  1. If you don't have nvm or nvm-windows installed, uninstall Node.js and npm first, so you don't have globally competing versions.
  2. Install nvm or nvm-windows
  3. Use nvm/nvm-windows to install Node.js 12.4.0 (should also install npm 6.9.0)
    • nvm install 12.4.0 && nvm use 12.4.0
  4. Delete your node_modules
  5. npm install --save-dev [email protected]
  6. npm install
  7. npm start ‍♀️

That's all I got. Hopefully someone else can help more, or this at least points you in the right direction.