Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NW.js and Electron platforms support #144

Closed
yerkeyzet opened this issue May 11, 2020 · 20 comments
Closed

NW.js and Electron platforms support #144

yerkeyzet opened this issue May 11, 2020 · 20 comments

Comments

@yerkeyzet
Copy link

Hi Team,

There is an issue when running node-rfc with NW.js or Electron on Windows 10. After running "npm start" it throws an error:
Uncaught Error: A dynamic link library (DLL) initialization routine failed.
?\C:\Storage\code\nwjs-hands-on\node_modules\node-rfc\lib\binding\sapnwrfc.node

It is easy to reproduce, just download my ready to run codes, npm install, and npm start - you will get the error in Dev tools console.
nwjs-hands-on.zip

I have tried rebuilding node-rfc with MSVS 2012, 2013, 2015, 2017, 2019 - none of them helped.
Command I used is:
npm install node-rfc --build-from-source --runtime=node-webkit --target=0.45.5 --target_arch=x64

On the other hand node-rfc works perfectly with Node.js app on the same Windows 10 machine.

What exact Visual Studio version do you use to compile C/C++ codes for this module?
Any ideas how to proceed further?

@yerkeyzet
Copy link
Author

You may need to run the following, if nw does not install automatically:

npm install nw@0.45.5-sdk

@bsrdjan
Copy link
Member

bsrdjan commented May 12, 2020

It happens on Windows only. Please feel free to try workarounds mentioned in napi#269, until the solution found.

@yerkeyzet
Copy link
Author

Thanks a lot for your feedback.

I went through the topic and found that one of the add-on developers could resolve this problem in his add-on a couple of days ago. I have asked him to update on the root cause, lets wait and see if it is applicable for node-rfc.

@yerkeyzet
Copy link
Author

He answered in the thread above, please have a look if you see any hints...

I tried step 2 from workaround below, but no result. Can you apply step 1 from your side?
1. Add set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DELAYLOAD:node.exe" ) to the Windows version of our native module in CMakeLists.txt
2. Add a delay load hook based on the code here: https://github.com/billti/create-vs-napi/blob/master/template/win_delay_load_hook.cc.txt

I also opened a new issue on their page based on your message, as the topic above was already closed and there is no guarantee that they will consider further activities of a closed topic.

@bsrdjan
Copy link
Member

bsrdjan commented May 13, 2020

I tried step 1 alone and it did not help but both steps together could eventually make a difference. Where exactly did you add the step 2 ?

The step 1 requires one line insert into CMakeLists.txt, after LTCG parameter at line 173:

target_link_options(${PROJECT_NAME} PUBLIC
    /NXCOMPAT
    /SWAPRUN:NET
    /OPT:REF
    /NOLOGO
    /LTCG
    /DELAYLOAD:node.exe
)

You can add the line and build sapnwrfc.node from source, running npm run prebuild.

Here the Windows build with step 1 only: sapnwrfc.node.zip

@yerkeyzet
Copy link
Author

  1. I put win_delay_load_hook.cc to these locations:

npm install node-gyp -g

C:\Users\Yerkebulan\AppData\Roaming\npm\node_modules\node-gyp\src\
C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\

  1. I modified C:\Storage\code\electron-quick-start_RFC\node_modules\node-rfc\CMakeLists.txt as you said, then ran npm run prebuild under C:\Storage\code\electron-quick-start_RFC\node_modules\node-rfc\, but error still exists.

  2. I downloaded your sapnwrfc.node file and placed it to C:\Storage\code\electron-quick-start_RFC\node_modules\node-rfc\lib\binding\

But still it gives me an error :(

What am I doing wrong?

My Node,js version is 14.2.0
Electron 8.2.5

@yerkeyzet
Copy link
Author

I also tried with Node 12.13.0 as you do -- but still an error.

My Windows 10 version is 1909
I compile with Visual Studio 2019

What is your VS version?

@bsrdjan
Copy link
Member

bsrdjan commented May 13, 2020

I am using VS2019 and used Node 12.13.0 because that version used in Electron 8.

@bsrdjan
Copy link
Member

bsrdjan commented May 13, 2020

Why NW.js is mentioned if initial/top comment, when the issue is about Electron?

@yerkeyzet
Copy link
Author

yerkeyzet commented May 14, 2020

I first faced this issue in NW.js, then tried in Electron and got same error there.

For now both of them don't work for me.

Here the Windows build with step 1 only: sapnwrfc.node.zip

I realized that you attached a build only with step 1. Can you please attach a build that worked for you on Windows 10 (after both steps applied)?

@bsrdjan
Copy link
Member

bsrdjan commented May 14, 2020

Sorry, no build worked for me on Windows and I did not test NW.

Please have a look into Electron documentation and try if any of methods described there eventually work for you?

None of them worked for me and I asked prebuild and Electron teams for help:

@yerkeyzet
Copy link
Author

I've been struggling with this issue for about a week and have tested all possible methods including this...

Ok, thanks for contacting with other teams!
I hope we will manage to create SAP RFC desktop apps with JS.

@vullnet-kurti
Copy link

vullnet-kurti commented Jul 13, 2020

I'm getting the same error with zeit/pkg.
Any updates on this? or any workarounds?

@yerkeyzet
Copy link
Author

Hi,

Unfortunately no updates so far...

@KSchala
Copy link

KSchala commented Oct 20, 2020

Also getting the error with zeit/pkg.. are there any updates?

Edit:
I think i could solve it, atleast not getting errors at the moment

Placed win_delay_load_hook.cc under ./src
Added /DELAYLOAD:node.exe at line 183 of CMakeLists.txt
Added src/win_delay_load_hook.cc at line 99

Here is a gist of the updated files

@bsrdjan bsrdjan changed the title Uncaught Error: A dynamic link library (DLL) initialization routine failed. SAP NWRFC SDK on NW.js and Electron and Windows 10 Oct 22, 2020
@bsrdjan
Copy link
Member

bsrdjan commented Oct 27, 2020

Tested again on Windows 10, with SAP NWRFC SDK 7.50 PL7 and node-rfc 2.3.0 and the same issue occurs.

The Process Monitor shows SDK libraries are found and for some reason still not loaded:

Screenshot 2020-10-27 at 12 26 58

Although it works on Linux and MacOS, the SAP NWRFC SDK is not supported on Electron platform. You may create SAP feature request for SAP Cloud Platform Connectivity Service subtopic of the SAP Cloud Platform - Integration Suite.

If you create the request, please share the link here.

@bsrdjan bsrdjan changed the title SAP NWRFC SDK on NW.js and Electron and Windows 10 NW.js and Electron platforms support Nov 3, 2020
@bung87
Copy link

bung87 commented Jan 26, 2021

I solve this by
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" )
I use cmake-js CMAKE_SHARED_LINKER_FLAGS equals /DELAYLOAD:node.exe
I install my native module runtime to electron and works fine on windows now.

target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB} ${OS_LIBS} while OS_LIBS contains "DelayImp.lib"

CMAKE_JS_LIB contains node.lib

also follow cmake Include N-API wrappers section

execute_process(COMMAND node -p "require('node-addon-api').include"
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        OUTPUT_VARIABLE NODE_ADDON_API_DIR
        )
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR} )

so I think here is 3 key points:

  1. LINK_FLAGS /DELAYLOAD:node.exe
  2. link library "DelayImp.lib" and node.lib
  3. include_directories "require('node-addon-api').include"

these mentioned in electron's document and cmake-js's readme but they don't provide a full example.

also I'd mention I literally set add_compile_definitions(NAPI_VERSION=6) since electron is combination of napi and node

@Zefau
Copy link

Zefau commented Oct 12, 2021

@bung87 just to confirm: you getting node-rfc running in Electron?

I keep getting the error message A dynamic link library (DLL) initialization routine failed.

Looks like https://github.com/SAP/node-rfc/blob/main/CMakeLists.txt has already partly been adapted based on your remarks?

Could you though provide a working example of CMakeLists.txt to successfully compile the sapnwrfc.node binding file?

My Node.js environment:

{
  node: '14.18.0',
  v8: '8.4.371.23-node.84',
  uv: '1.42.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.17.2',
  modules: '83',
  nghttp2: '1.42.0',
  napi: '8',
  llhttp: '2.1.3',
  openssl: '1.1.1l',
  cldr: '39.0',
  icu: '69.1',
  tz: '2021a',
  unicode: '13.0'
}

My Electron environment (v15.1.2):

{
  "platform": {
    "name": "win32",
    "arch": "x64",
    "release": "10.0.19043"
  },
  "env": {
    "SAPNWRFC_HOME": "C:\\Users\\Zefau\\Projects\\dc-dashboard\\build\\nwrfcsdk",
    "RFC_INI": "",
    "nwrfcsdk_lib_on_path": true
  },
  "versions": {
    "node": "16.5.0",
    "v8": "9.4.146.18-electron.0",
    "uv": "1.41.0",
    "zlib": "1.2.11",
    "brotli": "1.0.9",
    "ares": "1.17.1",
    "modules": "98",
    "nghttp2": "1.42.0",
    "napi": "8",
    "llhttp": "6.0.2",
    "openssl": "1.1.1",
    "icu": "69.1",
    "unicode": "13.0",
    "electron": "15.1.2",
    "chrome": "94.0.4606.71"
  }
}

@bsrdjan
Copy link
Member

bsrdjan commented Jul 4, 2023

Could you please try with node-rfc@3.0.0-rc.2

addition: and with updated test case: SAP-samples/node-rfc-samples/frameworks/electron-quick-start

@bsrdjan
Copy link
Member

bsrdjan commented Jul 17, 2023

Electron is supported as of node-rfc@3.1, also on Windows

@bsrdjan bsrdjan closed this as completed Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants