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

Build failure on Windows in node-gyp@11.1.0 due to GetModuleHandle LPCWSTR conversion issue #3126

Open
BohdanVV opened this issue Feb 12, 2025 · 2 comments · May be fixed by #3139
Open

Build failure on Windows in node-gyp@11.1.0 due to GetModuleHandle LPCWSTR conversion issue #3126

BohdanVV opened this issue Feb 12, 2025 · 2 comments · May be fixed by #3139

Comments

@BohdanVV
Copy link

BohdanVV commented Feb 12, 2025

Description

After upgrading to node-gyp@11.1.0, I encountered a build failure on Windows due to an incorrect function call in win_delay_load_hook.cc. The issue is caused by GetModuleHandle, which expects a wide string (LPCWSTR) but is receiving a narrow string (char*).

This happens on both local hardware and GitHub runners.

Error Message

C:\Users\myuser\AppData\Local\Yarn\Data\global\node_modules\node-gyp\src\win_delay_load_hook.cc(32,36): error C2664: 'HMODULE GetModuleHandleW(LPCWSTR)': cannot convert argument 1 from 'const char [12]' to 'LPCWSTR'

Additional Context

This issue appears to be introduced by changes in #2834, which were merged and released as part of node-gyp@11.1.0

Detailed logs (GitHub Actions run): logs from the failed build

Affected Versions

  • node-gyp: 11.1.0
  • Node.js: Any, I've tested w/ 18.x, 20.x, 22.x
  • OS: Windows 10 (x64), Windows GitHub runners

Proposed Fix

I'm not a C++ expert, but I attempted a modification in win_delay_load_hook.cc to explicitly use GetModuleHandleA (ANSI) instead of GetModuleHandle, which defaults to GetModuleHandleW (wide-character version).

Change this:

m = GetModuleHandle("libnode.dll");

to this:

m = GetModuleHandleA("libnode.dll");

If this sounds like a reasonable solution, I can open a PR.

Would appreciate any comments from the maintainers.

@zombieyang

StefanStojanovic added a commit to JaneaSystems/node-gyp that referenced this issue Mar 5, 2025
@StefanStojanovic StefanStojanovic linked a pull request Mar 5, 2025 that will close this issue
StefanStojanovic added a commit to JaneaSystems/node-gyp that referenced this issue Mar 5, 2025
StefanStojanovic added a commit to JaneaSystems/node-gyp that referenced this issue Mar 5, 2025
@PETEPEtrek
Copy link

Happened to me when I tried to build vscode , thanks!

@cclauss
Copy link
Contributor

cclauss commented Mar 10, 2025

Would it be possible to create a GitHub Action that fails because of this issue?

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

Successfully merging a pull request may close this issue.

3 participants