用npm安装node-postgres(在windows上)

我正在尝试使用npmWindows上安装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 

Solutions Collecting From Web of "用npm安装node-postgres(在windows上)"

每行

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

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

 npm install pg 

你检查了node-gyp的安装说明吗?

https://github.com/TooTallNate/node-gyp#installation

我最近遇到了Windows上node-gyp的问题,同时试图安装一个依赖于它的单独模块。 确保您安装了所需的每个项目。 具体关注这个部分:

对于64位版本的节点模块和本机模块,您还需要安装Windows 7 64位SDK。如果安装失败,请尝试卸载您先安装的任何C ++ 2010 x64&x86 Redistributable。

在OSx上见Peter Lyons回答(接受)。 Xcode版本选项为我工作。 https://stackoverflow.com/a/12825911/296765