nag*_*lzs 2 postgresql node.js
Windows 10 上的命令:
npm i pg-native
Run Code Online (Sandbox Code Playgroud)
抛出此构建错误:
? npm i pg-native
> libpq@1.8.7 install C:\Users\User\MyProject\frontend\node_modules\libpq
> node-gyp rebuild
C:\Users\User\MyProject\frontend\node_modules\libpq>if not defined npm_config_node_gyp (node "C:\Users\User\AppData\Roaming\npm
\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users
\User\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(55,5): error MSB8020: The build tools for Visual
Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build
tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution,
and then selecting "Retarget solution". [C:\Users\User\MyProject\frontend\node_modules\libpq\build\addon.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\User\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23
)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:191:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-g
yp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\User\MyProject\frontend\node_modules\libpq
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
Run Code Online (Sandbox Code Playgroud)
我尝试安装 Visual Studio/Express 2010,但没有帮助。还尝试安装 PostgreSQL 9.6 而不是 10,并将其 bin 目录添加到路径中。那没有帮助。
错误消息建议安装构建工具 v100,但在 Windows 10 上是不可能的。不支持(或者我不知道如何?)另一个建议的解决方案是“重新定位解决方案”,但这也是不可能的,因为给定的C:\Users\User\MyProject\frontend\node_modules\libpq\build\addon.vcxproj 解决方案文件不存在,因此无法重定向。
我是 node.js 的新手,一开始我完全迷失了。:-( 为什么 npm 不像其他语言那样有二进制包?(例如 Python 轮子、Java jar 等)我只想使用基本的 libpq 函数。为什么我必须为此安装 2GB 的工具链,然后意识到它行不通吗?太沮丧了。
顺便说一下,我也尝试安装 Windows SDK 7.1,因为它包含 v100 平台工具集,但它无法安装在 Windows 10 上。
有没有一种简单的方法可以将它安装为二进制文件?有没有人可以在 Windows 10 上编译这个?
无论如何用 v100 编译是没有意义的,因为它是一个恐龙。如果由于某种未知原因(我怀疑)必须使用 10 年前的编译器编译模块,那么将编译后的二进制文件简单地包含在包中仍然会好得多。(我碰巧知道 10 年前的 lipq.dll 可以与 PostgreSQL 10 一起使用。)
经过认真的工作数小时后,这里是解决方案。
注意:最初的问题是关于编译 pg-native。如果您只想编译 node-gyp,请忽略步骤 1,2。
将 PostgreSQL 10 安装到您的系统。
将 postgresql 安装的 bin 目录添加到 PATH 系统环境变量中。警告!它必须是系统环境,而不是用户环境!
确保安装了最新的 npm。
启动一个新的提升的 shell(cmd.exe 或 powershell)。例如“以管理员身份运行”。如果您在第 2 步之后没有重新启动系统,请确保您可以从该 shell 运行“pg_config”程序。
在同一终端中按此顺序运行以下命令。不要在两个命令之间关闭并重新打开终端!
npm install --global --production windows-build-tools
npm install -g node-gyp
npm install -g pg-native
Run Code Online (Sandbox Code Playgroud)
请注意,安装 node-gyp 需要管理员权限,因此您必须以管理员身份全局安装它,即使您只需要在一个项目中使用它。(我可能错了,但这是我的经验。)
另请注意,我可能在许多其他方面都错了,我可能不知道自己在做什么,但上述过程确实确实解决了问题。:-)
| 归档时间: |
|
| 查看次数: |
3535 次 |
| 最近记录: |