Closed kidswong999 closed 2 years ago
我们在 Windows 也遇到了这个问题,更新 VS C++ build tools 到 2019 及以上解决了。我们看看整体如何解决哈
改了electron版本之后打包会有问题。
在 Windows 上测试 Visual Code 2019 及以上正常,2017 因为一些接口不兼容导致 node-pty 编译原生模块失败。其它的原生模块(nsfw、spdlog)正常。
比如指定 vs2017 进行构建:
VCINSTALLDIR="C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild" "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Administrator\\repo\\ide-electron\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--openssl_fips=X" "--target=18.0.3" "--arch=x64" "--dist-url=https://electronjs.org/headers"
会报错如下:
gyp info find VS using VS2017 (15.9.28307.1974) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python310\python.exe
gyp info spawn args [
gyp info spawn args 'C:\\Users\\Administrator\\repo\\ide-electron\\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 'C:\\Users\\Administrator\\repo\\ide-electron\\node_modules\\node-pty\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\Administrator\\repo\\ide-electron\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\Administrator\\AppData\\Local\\node-gyp\\Cache\\18.0.3\\include\\node\\common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=C:\\Users\\Administrator\\AppData\\Local\\node-gyp\\Cache\\18.0.3',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\Administrator\\repo\\ide-electron\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\18.0.3\\\\<(target_arch)\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=C:\\Users\\Administrator\\repo\\ide-electron\\node_modules\\node-pty',
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 'C:\\Users\\Administrator\\repo\\ide-electron\\node_modules\\node-pty\\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn?[0m C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
?[0m?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn args?[0m [
?[0m?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn args?[0m 'build/binding.sln',
?[0m?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn args?[0m '/clp:Verbosity=minimal',
?[0m?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn args?[0m '/nologo',
?[0m?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn args?[0m '/p:Configuration=Release;Platform=x64'
?[0m?[37;40mgyp?[0m ?[0m?[32minfo?[0m ?[0m?[35mspawn args?[0m ]
?[0mBuilding the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
conpty.cc
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(240): error C2061: syntax error: identifier 'TracedGlobal<`template-type-parameter-1'>' [C:\Users\Administrator\repo\ide-electron\node_modules\node-pty\build\conpty.vcxproj]
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(335): note: see reference to class template instantiation 'v8::TracedGlobal<T>' being compiled
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(240): error C2334: unexpected token(s) preceding ':'; skipping apparent function body [C:\Users\Administrator\repo\ide-electron\node_modules\node-pty\build\conpty.vcxproj]
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(22): fatal error C1075: '{': no matching token found [C:\Users\Administrator\repo\ide-electron\node_modules\node-pty\build\conpty.vcxproj]
conpty_console_list.cc
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(240): error C2061: syntax error: identifier 'TracedGlobal<`template-type-parameter-1'>' [C:\Users\Administrator\repo\ide-electron\node_modules\node-pty\build\conpty_console_list.vcxproj]
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(335): note: see reference to class template instantiation 'v8::TracedGlobal<T>' being compiled
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(240): error C2334: unexpected token(s) preceding ':'; skipping apparent function body [C:\Users\Administrator\repo\ide-electron\node_modules\node-pty\build\conpty_console_list.vcxproj]
c:\users\administrator\appdata\local\node-gyp\cache\18.0.3\include\node\v8-traced-handle.h(22): fatal error C1075: '{': no matching token found [C:\Users\Administrator\repo\ide-electron\node_modules\node-pty\build\conpty_console_list.vcxproj]
Agent.cc
AgentCreateDesktop.cc
ConsoleFont.cc
ConsoleInput.cc
ConsoleInputReencoding.cc
ConsoleLine.cc
建议使用 Visual Code 2019 及以上的版本,或者直接降级 node-pty 到老版本,也许可行。
测试系统:Windows10 node版本:v14.19.2 node-gyp版本:v5.1.0
虽然我不知道为什么会出错,可能和node版本有关。 但是electron更改为17.4.3可以解决。
错误log