Skip to content

Conversation

kmashint
Copy link
Contributor

@kmashint kmashint commented Apr 18, 2025

With node@22 and MS VisualStudio 2022 BuildTools on Windows 10, the registry-js package was failing to build via node-gyp.
I had to upgrade to at least node-gyp@9 (latest node-gyp@11) for it to recognize VisualStudio 2022, and then there were build errors with main.cc that after some investigation appeared to need stricter declaration/casting. I've attempted a reasonable fix based on the errors although I'm not a C/C++ expert. This now npm installs, builds, and npm run test is successful.

$ node-gyp rebuild
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.11.6 found at "C:\Python\Python3\python.exe"

gyp info find VS using VS2022 (17.13.35931.197) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python\Python3\python.exe
gyp info spawn args [
gyp info spawn args '\\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 '\\registry-js\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args '\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '\\AppData\\Local\\node-gyp\\Cache\\22.14.0\\include\\node\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=\\AppData\\Local\\node-gyp\\Cache\\22.14.0',
gyp info spawn args '-Dnode_gyp_dir=\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\22.14.0\\\\<(target_arch)\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=\\registry-js',
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 '\\registry-js\\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn←[0m C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m [
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m 'build/binding.sln',
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m '/clp:Verbosity=minimal',
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m '/nologo',
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m '/nodeReuse:false',
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m '/p:Configuration=Release;Platform=x64'
←[37;40mgyp←[0m ←[32minfo←[0m ←[35mspawn args←[0m ]

  main.cc
\registry-js\src\main.cc(128,20): error C2665: '`anonymous-namespace'::CreateEntry': no overloaded function coul
d convert all the argument types [\registry-js\build\registry.vcxproj]
      \registry-js\src\main.cc(45,14):
      could be 'Napi::Object `anonymous-namespace'::CreateEntry(Napi::Env &,LPWSTR,LPWSTR,LPWSTR,DWORD)'
          \registry-js\src\main.cc(128,20):
          'Napi::Object `anonymous-namespace'::CreateEntry(Napi::Env &,LPWSTR,LPWSTR,LPWSTR,DWORD)': cannot convert arg
  ument 3 from 'const wchar_t [7]' to 'LPWSTR'
              \registry-js\src\main.cc(128,47):
              Conversion from string literal loses const qualifier (see /Zc:strictStrings)
      \registry-js\src\main.cc(128,20):
      while trying to match the argument list '(Napi::Env, WCHAR [16383], const wchar_t [7], LPWSTR, DWORD)'

\registry-js\src\main.cc(134,20): error C2665: '`anonymous-namespace'::CreateEntry': no overloaded function coul
d convert all the argument types [\registry-js\build\registry.vcxproj]
      \registry-js\src\main.cc(45,14):
      could be 'Napi::Object `anonymous-namespace'::CreateEntry(Napi::Env &,LPWSTR,LPWSTR,LPWSTR,DWORD)'
          \registry-js\src\main.cc(134,20):
          'Napi::Object `anonymous-namespace'::CreateEntry(Napi::Env &,LPWSTR,LPWSTR,LPWSTR,DWORD)': cannot convert arg
  ument 3 from 'const wchar_t [14]' to 'LPWSTR'
              \registry-js\src\main.cc(134,47):
              Conversion from string literal loses const qualifier (see /Zc:strictStrings)
      \registry-js\src\main.cc(134,20):
      while trying to match the argument list '(Napi::Env, WCHAR [16383], const wchar_t [14], LPWSTR, DWORD)'
...

Copy link
Contributor

@pimterry pimterry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - getting this released would be super useful! @sergiou87 this library is currently unusable in Node v22 (i.e. current LTS Node) without this change.

src/main.cc Outdated
@@ -42,7 +42,7 @@ LPWSTR utf8ToWideChar(std::string utf8) {
return result;
}

Napi::Object CreateEntry(Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data, DWORD dataLengthBytes)
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data, DWORD dataLengthBytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add const to the type parameter so we can avoid the const_cast uses?

Suggested change
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, LPWSTR type, LPWSTR data, DWORD dataLengthBytes)
Napi::Object CreateEntry(const Napi::Env& env, LPWSTR name, const LPWSTR type, LPWSTR data, DWORD dataLengthBytes)

Copy link
Contributor Author

@kmashint kmashint Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I adjusted. This isn't yet updating node-gyp in package.json, but needs at least node-gyp@9 to recognize MS VisualStudio 2022, e.g. [email protected] , or the latest now is 11.2.0.

@kmashint kmashint force-pushed the fix-node22-msvc2022 branch from 4e33838 to 756d73a Compare April 25, 2025 21:43
@kmashint kmashint force-pushed the fix-node22-msvc2022 branch from 756d73a to 256baa7 Compare April 26, 2025 18:39
@kmashint
Copy link
Contributor Author

I've updated to remove an unwanted change to package.json and setting node-gyp ^11.2.0 in devDependencies.

Copy link
Member

@sergiou87 sergiou87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It seems you will need to bump node too:

error [email protected]: The engine "node" is incompatible with this module. Expected version "^18.17.0 || >=20.5.0". Got "12.22.12"

@sergiou87
Copy link
Member

I think this is the line you need to change:

node-version: 12

@kmashint
Copy link
Contributor Author

kmashint commented Apr 28, 2025

Thanks, I increased the ci.yml to node-version: 18 .

@kmashint kmashint force-pushed the fix-node22-msvc2022 branch from 06c2047 to 3c5721b Compare April 29, 2025 16:44
@kmashint
Copy link
Contributor Author

Sorry for the missing adjustment to package-lock.json, I've updated that with npm install and yarn for yarn.lock.

Copy link
Member

@sergiou87 sergiou87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this!

@sergiou87 sergiou87 merged commit 3035027 into desktop:master May 20, 2025
1 check passed
@sergiou87 sergiou87 mentioned this pull request May 21, 2025
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 this pull request may close these issues.

3 participants