用npm安装node-postgres的问题(在windows上)[英] Issue installing node-postgres with npm (on windows)

本文是小编为大家收集整理的关于用npm安装node-postgres的问题(在windows上)的处理方法,想解了用npm安装node-postgres的问题(在windows上)的问题怎么解决?用npm安装node-postgres的问题(在windows上)问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

我正在尝试使用 npm 在 Windows 上安装 pg,但收到以下错误:

c:\Users\someone\Dropbox\somefolder>npm install -g pg
npm http GET https://registry.npmjs.org/pg
npm http 304 https://registry.npmjs.org/pg
npm http GET https://registry.npmjs.org/generic-pool/2.0.2
npm http 304 https://registry.npmjs.org/generic-pool/2.0.2

> pg@0.11.3 install C:\Users\someone\AppData\Roaming\npm\node_modules\pg
> node-gyp rebuild || (exit 0)


C:\Users\someone\AppData\Roaming\npm\node_modules\pg>node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-
yp\bin\node-gyp.js" rebuild
'pg_config' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\gyp", line 18, in <module>
    sys.exit(gyp.main(sys.argv[1:]))
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\__init__.py", line 511, in main
    return gyp_main(args)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\__init__.py", line 494, in gyp_main
    options.circular_check)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\__init__.py", line 133, in Load
    depth, generator_input_info, check, circular_check)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 2378, in Load
    depth, check)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 384, in LoadTargetBuildFile
    build_file_data, PHASE_EARLY, variables, build_file_path)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1053, in ProcessVariablesAndConditionsInD
    build_file)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1068, in ProcessVariablesAndConditionsInL
    ProcessVariablesAndConditionsInDict(item, phase, variables, build_file)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1027, in ProcessVariablesAndConditionsInD
    ProcessConditionsInDict(the_dict, phase, variables, build_file)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 904, in ProcessConditionsInDict
    variables, build_file)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1046, in ProcessVariablesAndConditionsInD
    build_file, key)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1046, in ProcessVariablesAndConditionsInD
    build_file, key)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1053, in ProcessVariablesAndConditionsInD
    build_file)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 1072, in ProcessVariablesAndConditionsInL
    expanded = ExpandVariables(item, phase, variables, build_file)
  File "C:\Users\someone\.node-gyp\0.8.16\tools\gyp\pylib\gyp\input.py", line 714, in ExpandVariables
    (contents, p.returncode))
Exception: Call to 'pg_config --libdir' returned exit status 1. 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:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\co
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:678:10)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "
gyp ERR! cwd C:\Users\someone\AppData\Roaming\npm\node_modules\pg
gyp ERR! node -v v0.8.16
gyp ERR! node-gyp -v v0.7.3
gyp ERR! not ok
pg@0.11.3 C:\Users\someone\AppData\Roaming\npm\node_modules\pg
└── generic-pool@2.0.2

我的版本如下:

c:\>node -v
v0.8.16

c:\>npm -v
1.1.69

当我检查存储库并尝试 node-gyp rebuild 时,我收到以下错误消息:

C:\Users\someone\Downloads\node-postgres.git>node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@0.8.3
gyp info using node@0.8.16 | win32 | ia32
gyp info spawn python
gyp info spawn args [ 'C:\\Users\\lamassey\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\lamassey\\Downloads\\node-postgres.git\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\lamassey\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\lamassey\\.node-gyp\\0.8.16\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\lamassey\\.node-gyp\\0.8.16',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\lamassey\\Downloads\\node-postgres.git',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Users\\lamassey\\Downloads\\node-postgres.git\\build',
gyp info spawn args   '-Goutput_dir=.' ]
'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 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\lamassey\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:420:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:678:10)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Users\\lamassey\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\lamassey\Downloads\node-postgres.git
gyp ERR! node -v v0.8.16
gyp ERR! node-gyp -v v0.8.3
gyp ERR! not ok

推荐答案

每行

'pg_config' is not recognized as an internal or external command

我只需要在尝试之前安装 PostgreSQL

npm install pg

本文地址:https://www.itbaoku.cn/post/1763756.html