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

fatal error: 'windows.h' file not found on macOS when using electron-rebuild to rebuild native-reg in Electron apps #35

Closed
oalfroukh opened this issue Nov 29, 2022 · 8 comments

Comments

@oalfroukh
Copy link

Hi,

/Users/omaralfroukh/Desktop/project/node_modules/node-addon-api/napi.h:32:6: error: Exception support not detected.       Define either NAPI_CPP_EXCEPTIONS or NAPI_DISABLE_CPP_EXCEPTIONS.
    #error Exception support not detected. \
     ^
../reg.cc:4:10: fatal error: 'windows.h' file not found
#include <windows.h>
         ^~~~~~~~~~~
2 errors generated.
make: *** [Release/obj.target/reg/reg.o] Error 1
  ⨯ node-gyp failed to rebuild '/Users/omaralfroukh/Desktop/project/node_modules/@aabuhijleh/native-reg'.
For more information, rerun with the DEBUG environment variable set to "electron-rebuild".
  • I'm not an expert in the native modules, but I think to fix that issue we have to add a condition to using this library on Windows OS only, here is the fix that needs to add to binding.gyp file:
"conditions": [
        [
          "OS==\"win\"",
          {
            "sources": ["reg.cc"]
          }
        ]
      ],
  • So binding.gyp file should be something like this:
{
  "targets": [
    {
      "target_name": "reg",
      "dependencies": [
        "<!(node -p \"require('node-addon-api').gyp\")"
      ],
      "include_dirs": [
        "<!@(node -p \"require('node-addon-api').include\")",
      ],
      "conditions": [
        [
          "OS==\"win\"",
          {
            "sources": ["reg.cc"]
          }
        ]
      ],
      "msvs_settings": {
        "VCCLCompilerTool": {
          "AdditionalOptions": [
            "/std:c++17"
          ],
          "ExceptionHandling": 1
        },
      }
    }
  ]
}

Thanks a lot!

@simonbuchan
Copy link
Owner

Thanks for the report. This has gone back and forwards a bit, ideally there simply isn't any build or source files in the package as we can feasibly prebuild them for every platform supported by Windows, since this is N-API so there's no reason to rebuild it.

I'll have to refresh myself to make sure I'm not breaking any of these earlier changes, but your suggested change looks good. I'm certainly happy to publish it as a @next tagged build for now.

@oalfroukh
Copy link
Author

oalfroukh commented Nov 29, 2022

Hi @simonbuchan I'm using @aabuhijleh/native-reg v0.3.4, I didn't notice there are tags on this repo, I'll re-check v1.0.0 and I'll get back to you.
Thanks!

@simonbuchan
Copy link
Owner

1.1.0 is the current latest tag, but it looks like you would be fixed by 0.3.6, which fixed #23. That looks like a dup of this, fixed via the rather brute-force method of simply removing the binding.gyp 👌

@oalfroukh
Copy link
Author

The same issue on the latest version 1.1.0 on macOS while adding that conditions to the binding.gyp file also fixed the issue. I checked v0.3.6 seems it's OK, can we use that version or it has a bugs?

@simonbuchan
Copy link
Owner

Right, looks like 1.1.0 restored binding.gyp to fix Windows ARM, which re-broke #23. Only difference is from 0.3.6 to 1.0.0 is it drops earlier node support, so take your pick of those in the short term.

@simonbuchan
Copy link
Owner

Ok I've published 1.1.1 with your condition change in the @next tag - let me know if it works for you!

@oalfroukh
Copy link
Author

Ok I've published 1.1.1 with your condition change in the @next tag - let me know if it works for you!

Hi @simonbuchan,
Yes, v1.1.1 is OK on both Windows and macOS, thanks for the publish.

@simonbuchan
Copy link
Owner

Good to hear! I'm mark it as latest then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants