node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

pg doesn't install with npm on Windows

Open chowey opened this issue 15 years ago • 20 comments

There is a problem installing pg on Windows with npm. This is due to the script that pg tries to run on install. The error message looks like this:

c:\node>npm install pg

> [email protected] install c:\node\node_modules\pg
> node-waf configure build || true

'node-waf' is not recognized as an internal or external command,
operable program or batch file.
'true' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! error installing [email protected] Error: [email protected] install: `node-waf configure
build || true`
... (blah blah blah)

As you can see, "true" is not a recognized command on Windows.

Is there a Windows-friendly way to rephrase the install script, something other than "node-waf configure build || true"? I know that something like "node-waf configure build || exit 0" would work, but I don't know what that does in Linux or Mac OSX.

chowey avatar Nov 14 '11 00:11 chowey

Hello,

As we can see in: https://github.com/isaacs/npm/commit/1ae770e6314f70ac87d6bd9ef43d12ae067b17e6

But now, when I try to install, I just get a "Unknown System"...

C:\Program Files (x86)\nodejs>npm install pg npm ERR! error installing [email protected] Error: connect Unknown system errno 10060 npm ERR! error installing [email protected] at errnoException (net.js:614:11) npm ERR! error installing [email protected] at Object.afterConnect as oncomplete npm ERR! Error: connect Unknown system errno 10060 npm ERR! at errnoException (net.js:614:11) npm ERR! at Object.afterConnect as oncomplete npm ERR! Report this entire log at: npm ERR! http://github.com/isaacs/npm/issues npm ERR! or email it to: npm ERR! [email protected] npm ERR! npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (x86)\nodejs\node_modules\npm\bin\npm-cli.js" "install" "pg" npm ERR! cwd C:\Program Files (x86)\nodejs npm ERR! node -v v0.6.1 npm ERR! npm -v 1.0.105 npm ERR! code Unknown system errno 10060 npm ERR! npm ERR! Additional logging details can be found in: npm ERR! C:\Program Files (x86)\nodejs\npm-debug.log npm not ok

fabioboris avatar Nov 15 '11 00:11 fabioboris

Hrm, the patch works for me. Do you have "node-waf" on your system? Or it may be some other problem with npm.

You can also try my updated patch, which uses a different approach. It has two files:

  • Use "bin/true.cmd" at df3fb1847052ec4e6a6ff357d827b957b57a149e
  • Use "lib/utils/exec.js" at ce9d148893d78d009c0daea27f933c94d6d6ea87

However, the point of this issue was that we can also make the pg install script more Windows-friendly instead of trying to rewrite npm. I was hoping someone with more cross-platform experience could suggest an alternate to using "node-waf configure build || true" that will work everywhere.

chowey avatar Nov 15 '11 01:11 chowey

A temporary fix for Windows users is to create a file called "true.cmd" with the following contents:

exit 0

and place it in the same folder as node.exe.

chowey avatar Nov 21 '11 00:11 chowey

thanks chowey. Off the top of your head do you know any exit code both unix and windows shell will accept? Should be a super easy patch once that's figured out.

brianc avatar Nov 28 '11 05:11 brianc

Is it worth building the c++ bindings at all any more? Are they still maintained? I thought they were deprecated in favor of the native ones.

defunctzombie avatar Nov 28 '11 05:11 defunctzombie

Hmmm...I believe the c++ bindings should work just fine in node v0.4.x and node v0.6.x. They're not deprecated and are still maintained for non-windows systems. Once the 'addon story' for windows is complete I'd like to get the c++ bindings working there as well, actually.

I suppose for the time being I could check & see if the system is windows & abort the build process at the beginning with an 'exit 0'

brianc avatar Nov 28 '11 05:11 brianc

I don't know any exit code that unix/windows/mac os all have in common. I was looking for a bit but didn't find one. I saw one suggestion to use color as a windows-alternative to true, but alas unix doesn't have a color command.

Maybe do something like node-waf configure build || true || color? Cryptic, but should work.

color doesn't cause the current session to exit, like exit 0 does. I don't think it makes a difference for our purposes but it is probably better practice.

chowey avatar Nov 28 '11 19:11 chowey

Is it not possible to just have the wscript file detect if libpg is available and exit cleanly if it is not? It is python so you could just do the exit there.

defunctzombie avatar Nov 28 '11 19:11 defunctzombie

The point is that I don't have node-waf on my computer. This shouldn't block me from installing pg entirely.

chowey avatar Nov 28 '11 21:11 chowey

The reference about the color command being a substitute to true comes from ss64.com:

true

Do nothing, returning a zero (true) exit status

...

Equivalent Windows command: The COLOR command can be used be used to set an %errorlevel%

chowey avatar Nov 29 '11 13:11 chowey

you can use npm install pg --force in the meantime

brianc avatar Dec 01 '11 21:12 brianc

Erm, I don't think this works. --force just forces npm to fetch the tarball newly from the npm registry.

chowey avatar Dec 02 '11 18:12 chowey

Per isaacs/npm#1625, node-waf configure build || (exit 0) can also be used in unix. In fact, the current version of npm just switched to this instead of || true. Can anyone verify it works in *nix?

chowey avatar Dec 03 '11 21:12 chowey

Adding the true.cmd worked for me. But I noted another smaller issue: npm installs the package in whatever directory your command window is at that moment instead of in the Users\AppData\Roaming\npm\node_modules.

samuelbosch avatar Dec 08 '11 20:12 samuelbosch

That's how npm works. If you want to do a global install into %AppData%, you need to use npm install pg -g.

chowey avatar Dec 09 '11 14:12 chowey

Thanks for clarifying that, as you probably guessed I'm new to node.js and its ecosystem.

samuelbosch avatar Dec 09 '11 18:12 samuelbosch

Hi all,

I'm using node v0.6.5 MSI package that includes npm 1.1.0-alpha-6, but seems that the problem is still there.

Adding true.cmd file worked for me, this workaround will be included in NPM?

gimmi avatar Dec 11 '11 14:12 gimmi

Also, seems that the commit

https://github.com/isaacs/npm/commit/1ae770e6314f70ac87d6bd9ef43d12ae067b17e6

reported by @fabioboris seems that has not been included in any release yet

gimmi avatar Dec 11 '11 14:12 gimmi

npm has changed node-waf configure build || true to node-waf configure build || (exit 0) in its internal implementation.

pg should do the same.

This should handle it without the true.cmd trick.

chowey avatar Dec 11 '11 20:12 chowey

Thanks very much.

chowey avatar Dec 13 '11 04:12 chowey