Failed to rebuild dependencies with npm

2019-07-10 02:31发布

问题:

As I am trying to push my nodejs app which is working fine locally to heroku, here is what I get in terminal:

dcaclab@ubuntu:~/RubymineProjects/nodejs_consumer$ git push heroku master
Counting objects: 1417, done.
Compressing objects: 100% (1195/1195), done.
Writing objects: 100% (1417/1417), 2.02 MiB | 22 KiB/s, done.
Total 1417 (delta 247), reused 0 (delta 0)

-----> Node.js app detected
-----> Resolving engine versions
       Using Node.js version: 0.10.6
       Using npm version: 1.2.21
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
       npm WARN package.json node-example@0.0.1 No repository field.
       npm WARN package.json node-example@0.0.1 No readme data.
       npm WARN package.json node@0.0.0 No repository field.
       npm WARN package.json faye-websocket@0.4.0 No repository field.
       npm WARN package.json faye-websocket@0.4.0 'repositories' (plural) Not supported.
       npm WARN package.json Please pick one as the 'repository' field
       npm WARN package.json rbytes@0.0.2 No repository field.
       npm WARN package.json node-example@0.0.1 No repository field.
       npm WARN package.json node-example@0.0.1 No readme data.
       npm WARN package.json node@0.0.0 No repository field.
       npm WARN package.json faye-websocket@0.4.0 No repository field.
       npm WARN package.json faye-websocket@0.4.0 'repositories' (plural) Not supported.
       npm WARN package.json Please pick one as the 'repository' field
       npm WARN package.json rbytes@0.0.2 No repository field.

       > weak@0.2.2 install /tmp/build_f86ikz343m5u/node_modules/dnode/node_modules/weak
       > node-gyp rebuild

       gyp http GET http://nodejs.org/dist/v0.10.6/node-v0.10.6.tar.gz
       gyp http 200 http://nodejs.org/dist/v0.10.6/node-v0.10.6.tar.gz
       make: Entering directory `/tmp/build_f86ikz343m5u/node_modules/dnode/node_modules/weak/build'
         CXX(target) Release/obj.target/weakref/src/weakref.o
         SOLINK_MODULE(target) Release/obj.target/weakref.node
         SOLINK_MODULE(target) Release/obj.target/weakref.node: Finished
         COPY Release/weakref.node
       make: Leaving directory `/tmp/build_f86ikz343m5u/node_modules/dnode/node_modules/weak/build'

       > rbytes@0.0.2 install /tmp/build_f86ikz343m5u/node_modules/shoe/node_modules/sockjs/node_modules/rbytes
       > node-waf configure build

       sh: node-waf: not found
       npm ERR! weird error 127
       npm ERR! not ok code 0
 !     Failed to rebuild dependencies with npm
 !     Heroku push rejected, failed to compile Node.js app

To git@heroku.com:dcaclab-simulator.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:dcaclab-simulator.git'

here is my package.json file:

{
  "name": "node-example",
  "version": "0.0.1",
  "dependencies": {
    "dnode": "1.0.5",
    "shoe": "0.0.10"
  },
  "engines": {
    "node": "0.10.x",
    "npm": "1.2.x"
  }
}

Any idea please?

EDIT

Tried to use node 0.8, here is what I got:

dcaclab@ubuntu:~/RubymineProjects/nodejs_consumer$ git push heroku master
Counting objects: 1420, done.
Compressing objects: 100% (1198/1198), done.
Writing objects: 100% (1420/1420), 2.02 MiB | 24 KiB/s, done.
Total 1420 (delta 249), reused 0 (delta 0)

-----> Node.js app detected
-----> Resolving engine versions
       Using Node.js version: 0.8.23
       Using npm version: 1.2.21
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
       npm WARN package.json node-example@0.0.1 No repository field.
       npm WARN package.json node-example@0.0.1 No readme data.
       npm WARN package.json node@0.0.0 No repository field.
       npm WARN package.json rbytes@0.0.2 No repository field.
       npm WARN package.json faye-websocket@0.4.0 No repository field.
       npm WARN package.json faye-websocket@0.4.0 'repositories' (plural) Not supported.
       npm WARN package.json Please pick one as the 'repository' field
       npm WARN package.json node-example@0.0.1 No repository field.
       npm WARN package.json node-example@0.0.1 No readme data.
       npm WARN package.json node@0.0.0 No repository field.
       npm WARN package.json rbytes@0.0.2 No repository field.
       npm WARN package.json faye-websocket@0.4.0 No repository field.
       npm WARN package.json faye-websocket@0.4.0 'repositories' (plural) Not supported.
       npm WARN package.json Please pick one as the 'repository' field

       > weak@0.2.2 install /tmp/build_1uw8vrtz5u7yu/node_modules/dnode/node_modules/weak
       > node-gyp rebuild

       gyp http GET http://nodejs.org/dist/v0.8.23/node-v0.8.23.tar.gz
       gyp http 200 http://nodejs.org/dist/v0.8.23/node-v0.8.23.tar.gz
       make: Entering directory `/tmp/build_1uw8vrtz5u7yu/node_modules/dnode/node_modules/weak/build'
         CXX(target) Release/obj.target/weakref/src/weakref.o
         SOLINK_MODULE(target) Release/obj.target/weakref.node
         SOLINK_MODULE(target) Release/obj.target/weakref.node: Finished
         COPY Release/weakref.node
       make: Leaving directory `/tmp/build_1uw8vrtz5u7yu/node_modules/dnode/node_modules/weak/build'

       > rbytes@0.0.2 install /tmp/build_1uw8vrtz5u7yu/node_modules/shoe/node_modules/sockjs/node_modules/rbytes
       > node-waf configure build

       Checking for program g++ or c++          : /usr/bin/g++ 
       Checking for program cpp                 : /usr/bin/cpp 
       Checking for program ar                  : /usr/bin/ar 
       Checking for program ranlib              : /usr/bin/ranlib 
       Checking for g++                         : ok  
       Checking for node path                   : not found 
       Checking for node prefix                 : ok /tmp/node-node-Rkll 
       'configure' finished successfully (0.027s)
       Waf: Entering directory `/home/dcaclab/RubymineProjects/nodejs_consumer/node_modules/shoe/node_modules/sockjs/node_modules/rbytes/build'
       Waf: Leaving directory `/home/dcaclab/RubymineProjects/nodejs_consumer/node_modules/shoe/node_modules/sockjs/node_modules/rbytes/build'
       Traceback (most recent call last):
         File "/tmp/node-node-Rkll/bin/node-waf", line 16, in <module>
           Scripting.prepare(t, os.getcwd(), VERSION, wafdir)
         File "/tmp/node-node-Rkll/bin/../lib/node/wafadmin/Scripting.py", line 145, in prepare
           prepare_impl(t, cwd, ver, wafdir)
         File "/tmp/node-node-Rkll/bin/../lib/node/wafadmin/Scripting.py", line 135, in prepare_impl
           main()
         File "/tmp/node-node-Rkll/bin/../lib/node/wafadmin/Scripting.py", line 188, in main
           fun(ctx)
         File "/tmp/node-node-Rkll/bin/../lib/node/wafadmin/Scripting.py", line 386, in build
           return build_impl(bld)
         File "/tmp/node-node-Rkll/bin/../lib/node/wafadmin/Scripting.py", line 405, in build_impl
           bld.compile()
         File "/tmp/node-node-Rkll/bin/../lib/node/wafadmin/Build.py", line 268, in compile
           os.chdir(self.bldnode.abspath())
       OSError: [Errno 2] No such file or directory: '/home/dcaclab/RubymineProjects/nodejs_consumer/node_modules/shoe/node_modules/sockjs/node_modules/rbytes/build'
       npm ERR! weird error 1
       npm ERR! not ok code 0
 !     Failed to rebuild dependencies with npm
 !     Heroku push rejected, failed to compile Node.js app

To git@heroku.com:dcaclab-simulator.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:dcaclab-simulator.git'

回答1:

So the rbytes package has been unchanged for 2 years, and in that time node has switched from the node-waf build system to node-gyp. As of node v0.10.0, node-waf is no longer included thus the sh: node-waf: not found error message. I think you have a few options (in order of preference):

  1. Use a more modern module instead of rbytes
  2. Convince the author of rbytes to update to support recent node and release a new version
  3. Fork rbytes and fix it yourself
  4. Set your package.json engine to node 0.8 and try again

EDIT

Well, error message #2 still looks like rbytes doesn't build properly. I'd have to dig into that package particularly to understand the error. Not sure how/why it's working for you locally but having problems on heroku, but I think it's time for the rbytes maintainer to do some maintenance.



回答2:

I had this issue after a fresh compile of the latest version of node.js in Ubuntu. As per Peter Lyon's advice, the issue has to do with node-gyp not being around. Usually, when installing from a pre-compiled package this is not a problem (aptitude and the rhel repos usually include node-gyp by default).

However, if you are building from source, it's likely node-gyp isn't there, which is what caused the issue in my case.

This solved it for me:

sudo npm install -g node-gyp

After that, running npm install worked fine, the errors vanished!



回答3:

Stay away from rbytes, and in general from any un-maintained module, especially one doing something important and subtle like crypto. You can get everything you need from using Node's native crypto module. See http://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback :

crypto.pseudoRandomBytes(256)


回答4:

I faced same issue, just remove existing node_module directory. and then run npm install. That's it