安装 pg-native 依赖项时出现问题

问题描述 投票:0回答:1

我目前正在努力将 pg-native 依赖项安装到我的项目文件夹中。 当我尝试运行我的index.js时,它说它无法“解决依赖关系pg-native”,尽管我不相信我调用它。 但是,假设我这样做了,我尝试安装依赖项并在尝试执行以下操作时收到此错误屏幕:

C:\Users\jmurr\Documents\MSDPP-Map>npm i pg-native

> [email protected] install C:\Users\jmurr\Documents\MSDPP-Map\node_modules\libpq
> node-gyp rebuild


C:\Users\jmurr\Documents\MSDPP-Map\node_modules\libpq>if not defined npm_config_node_gyp (node "C:\Users\jmurr\AppData\Roaming\nvm\v8.11.4\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\jmurr\AppData\Roaming\nvm\v8.11.4\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
'pg_config' is not recognized as an internal or external command,
operable program or batch file.
gyp: Call to 'pg_config --libdir' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\jmurr\AppData\Roaming\nvm\v8.11.4\node_modules\npm\node_modules\node-gyp\lib\configure.js:336:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\jmurr\\AppData\\Roaming\\nvm\\v8.11.4\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\jmurr\Documents\MSDPP-Map\node_modules\libpq
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jmurr\AppData\Roaming\npm-cache\_logs\2019-11-14T02_44_05_069Z-debug.log

在安装之前,我已尽力正确设置所有内容,如 Windows 部分所述:https://www.npmjs.com/package/pg-native。 然而,它仍然不起作用。 我可能做错了其中一件事,希望这里有人可以帮助我解决过去几天试图解决这个问题的挫败感。 谢谢您的宝贵时间!

javascript node.js postgresql npm pg
1个回答
0
投票

我遇到了同样的问题,我按照 https://www.npmjs.com/package/pg-native 中的步骤进行操作;假设您根据错误消息使用的是 Windows,但还需要安装 python。

对于我来说,这是我遵循的具体步骤:

  1. https://www.python.org/downloads/

    下载并安装 Python
  2. https://visualstudio.microsoft.com/downloads/

    下载并安装 Visual Studio 2022 Community Edition(使用 c++ 安装桌面开发,保留默认值)
  3. http://www.postgresql.org/download/windows/

    下载并安装 Postgres
  4. C:\Program Files\PostgreSQL\16\bin
    添加到路径中。请记住重新打开您已经打开的任何命令提示符,否则您可能会继续收到有关缺少组件的错误,例如
    pg_config
    ,这来自 Postgres bin 文件夹。

  5. 满足上述所有条件后,您应该能够毫无问题地安装

    pg-native

npm i pg-native

added 13 packages, changed 1 package, and audited 655 packages in 13s

172 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

© www.soinside.com 2019 - 2024. All rights reserved.