LeoIannacone / npm2deb

tool to help debianize Node.js modules
GNU General Public License v3.0
46 stars 34 forks source link

cannot create modules that depend on nan #8

Closed andrewrk closed 10 years ago

andrewrk commented 10 years ago

For example leveldown has binding.gyp with:

      , "include_dirs"  : [
            "<!(node -e \"require('nan')\")"
        ]
$ npm2deb create leveldown
Traceback (most recent call last):
  File "/usr/local/bin/npm2deb", line 7, in <module>
    sys.exit(main(sys.argv))
  File "/usr/local/lib/python2.7/dist-packages/npm2deb/scripts.py", line 132, in main
    args.func(args)
  File "/usr/local/lib/python2.7/dist-packages/npm2deb/scripts.py", line 264, in create
    npm2deb.start()
  File "/usr/local/lib/python2.7/dist-packages/npm2deb/__init__.py", line 76, in start
    self.download()
  File "/usr/local/lib/python2.7/dist-packages/npm2deb/__init__.py", line 315, in download
    raise ValueError(exception)
ValueError: Error downloading package leveldown
npm http GET https://registry.npmjs.org/leveldown/-/leveldown-0.10.2.tgz
npm http 200 https://registry.npmjs.org/leveldown/-/leveldown-0.10.2.tgz
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/bindings
npm http 200 https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/nan/-/nan-0.6.0.tgz
npm http 200 https://registry.npmjs.org/nan/-/nan-0.6.0.tgz

> leveldown@0.10.2 install /home/admin/js/leveldown/node_modules/leveldown
> node-gyp rebuild

/bin/sh: 1: node: not found
gyp: Call to 'node -e "require('nan')"' returned exit status 127. 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 (/usr/share/node-gyp/lib/configure.js:344:16)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:809:12)
gyp ERR! System Linux 3.2.0-4-amd64
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/admin/js/leveldown/node_modules/leveldown
gyp ERR! node -v v0.10.29
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! leveldown@0.10.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the leveldown@0.10.2 install script.
npm ERR! This is most likely a problem with the leveldown package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls leveldown
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-4-amd64
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "leveldown"
npm ERR! cwd /home/admin/js/leveldown
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.4
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/admin/js/leveldown/npm-debug.log
npm ERR! not ok code 0

See node-ws for an already completed example that has this setup.

andrewrk commented 10 years ago

Note this also prevents npm2deb from working for projects that depend (possibly indirectly) on modules that have this issue.

LeoIannacone commented 10 years ago

Just a hint:

This is not a problem directly connected to npm2deb, but it's related to nodejs binary name in Debian (some scripts expect a node binary instead).

To quickly workaround this issue, please set an alias in this way: $ alias node='nodejs'

For more info about node binary renaming please refer to Debian wiki page Node.js Policy (Manual).

andrewrk commented 10 years ago

Thanks this helped me get past the issue. Although I had to sudo cp /usr/bin/nodejs /usr/bin/node temporarily, it seems the alias didn't work in the subshell that npm2deb spawned.

LeoIannacone commented 10 years ago

The alias does not work. Confirmed.

The sudo cp /usr/bin/nodejs /usr/bin/node is the only workaround.

I don't know how to fix this internally to npm2deb, since it is more a system wide problem. We should reconsider to use node as Node.js binary? @kapouer

kapouer commented 10 years ago

@andrewrk you're supposed to add a quilt patch to binding.gyp to rename node to nodejs. @LeoIannacone did you forget https://wiki.debian.org/Javascript/Nodejs/Manual#Patching_binaries_shebang ?

andrewrk commented 10 years ago

Actually the example I gave can be quilt patched to be deleted. For example see http://anonscm.debian.org/gitweb/?p=collab-maint/node-ws.git;a=blob;f=debian/patches/rm-redundant-legacy-include;h=391b8077ef335a9073c85fd70bd989be036bd762;hb=refs/heads/master

It's only a problem when using npm2deb create.

LeoIannacone commented 10 years ago

@kapouer no, absolutely. The problem is if nan is going to be downloaded via npm.. it will use "node" binary (since it's not patched).. so "npm install" fails.

andrewrk commented 10 years ago

maybe when npm2deb spawns a subshell to run the npm install command, it could modify PATH in the subshell only and add a directory which provides node as a link to /usr/bin/nodejs. This would avoid tampering with the system but still allow npm install to succeed for the duration of npm2deb create

kapouer commented 10 years ago

@LeoIannacone that's precisely the reason why nodejs-legacy package is available - to make sure people can use npm as they do without the rename.

LeoIannacone commented 10 years ago

@andrewrk @kapouer I think as fast workaround I would suggest users to install nodejs-legacy.

For the future, I would think something new: now npm2dep run a "npm install" against the module.

Since the most of them (node modules) comes from github I could edit npm2deb to get source directly from github instead of getting the npm version..

I will think on it.

kapouer commented 10 years ago

Hey did you notice that was in console output of the failed build ?

npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
LeoIannacone commented 10 years ago

Hi,

I'm marking this issue as "won't fix" since it is related to nodejs binary renaming.

Consider to install node-legacy as workaround while debianize this kind of modules.