10

我正在尝试使用 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
4

3 回答 3

6

每行

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

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

npm install pg
于 2013-01-23T21:41:35.720 回答
2

您是否查看过 node-gyp 的安装说明?

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

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

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

于 2013-01-23T20:32:00.367 回答
0

在 OSx 上,请参阅 Peter Lyons 的回答(已接受)。Xcode 版本选项对我有用。 https://stackoverflow.com/a/12825911/296765

于 2013-10-08T14:23:14.943 回答