【问题标题】:Issue installing node-postgres with npm (on windows)使用 npm 安装 node-postgres 时出现问题(在 Windows 上)
【发布时间】:2013-01-07 09:35:31
【问题描述】:

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

【问题讨论】:

  • 回答我自己的问题,这只是在尝试 npm install pg 之前没有安装 PostgreSQL 的结果。此外,pg_config 必须在您的系统路径中。
  • 不要将您的解决方案作为评论发布,而是将其作为答案发布在下方,您可以在 48 小时后接受。

标签: windows node.js postgresql npm


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    每行

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

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

    npm install pg
    

    【讨论】:

    • Note) 在 Windows 8.1 上我无法让 pg_env.bat 提交对环境变量的更改,所以我不得不手动添加它们。可以在版本后的根文件夹中找到(C:\Program Files\PostgreSQL\9.3\pg_env.bat)
    • 缺少C:\Program Files\PostgreSQL\9.3\bin的路径
    【解决方案3】:

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

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

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

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

    【讨论】:

    • 我使用的是 32 位,但作为预防措施,我重新安装了 C++ 2010(和 SP1)。这个错误原来只是由于在尝试“npm install pg”之前没有安装 PostgreSQL(并将 pg_config 放在系统路径中)。
    • @i3enhamin 啊,您可以回答自己的问题并接受它,以便将来看到此页面的任何人都可以轻松知道该怎么做。
    猜你喜欢
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 2023-01-01
    相关资源
    最近更新 更多