I have just deployed my first production Meteor app, but ran into a pretty significant issue. When I tried to run my app, I get the following error:
/home/hiapp/bundle/programs/server/node_modules/fibers/future.js:173
throw(ex);
^
Error: /home/hiapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/build/Release/bcrypt_lib.node: invalid ELF header
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at bindings (/home/hiapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:74:15)
at Object.<anonymous> (/home/hiapp/bundle/programs/server/npm/npm-bcrypt/node_modules/bcrypt/bcrypt.js:1:97)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Through some research, it seems that the issue is that bcrypt is platform-specific, and because my development is on OS X 10.10, but my production server is on Ubuntu 14.04, there-in lies the problem. My work around was to run npm install bcrypt
from the programs/server folder, then copy that from programs/server/node_modules/bcrypt
to programs/server/npm
. This seems like a lot of manual steps.
I am just about to re-deploy my app with some fixes, and I am worried that I am going to have to again perform the same steps. Is there a better way to deploy a Meteor app where you do not run into this issue? My procedure currently is:
meteor build
I am guessing the auto-refresh will be broken as the first time the server tries to load the new libraries it will explode in fiery glory. Would it be better to simply clone the GIT repo on the server and do the build straight from there, or can I use mup
or any other tools to help smoothen the deployment process?
There are two ways of getting around this time-consuming problem which are totally dependant on how you deploy.
If you are manually deploying your app then make sure that you are using node v0.10.361 and only that. Meteor does not work well with node v0.12.x. More specifically, the fibers module causes a lot of problems, it chokes on various errors2.
The following is the procedure that fixed it for me3, 4:
Remove the bcrypt module from the npm
directory:
$ cd path_to_your_app/bundle/programs/server
$ rm -rf npm/npm-bcrypt/node_modules/bcrypt/
Install the bcrypt module into the node_modules
directory first. This builds bcrypt against the server's OS:
$ npm install bcrypt
Move the newly created bcrypt module into the npm
directory:
$ cp -r node_modules/bcrypt npm/npm-bcrypt/node_modules/bcrypt
Finally, restart the app, mogodb and any web server processes such as nginx6, through upstart if you have it configured. Under the heading sanity steps below you can perform if the steps outlined above have not fixed it for you.
If you are using mup then the process is much easier as other answers on this thread point out. However, there are cases where errors still arise including the invalid ELF header
error. Make sure you have the most recent version of mup npm update mup -g
.
The first step is to remove any pre-existing app and nodejs package. Mup installs the app into /opt/
and within there you can find your_app
and nodejs
. Remove them.
Verify that you have the correct node version, 0.10.36 only1 and the following settings, in the mup.json
file:
{
...
"setupMongo": true,
"setupNode": true,
"nodeVersion" : "0.10.36",
"setupPhantom": true,
"enableUploadProgressBar": true,
// Application name (No spaces)
"appName": "your_app",
// Location of app (local directory)
"app": ".",
...
}
Run:
$ mup setup
$ mup deploy
Navigate to the server
folder on your server and rebuild modules:
$ cd /opt/your_app/app/programs/server
$ npm rebuild
$ npm install
Optional: $ sudo npm update node-gyp -g
Finally, restart the app, mogodb and any web server processes such as nginx6. After the above steps, you may want to look at sanity steps below for more debugging options.
There are a few other steps you can perform:
Note that apache may also bind itself to the same port that nginx is running on. Look at your app's error logs and your web server's error logs to see if there are any issues. Stop apache via sudo service apache2 stop
or brute force close (not recommended) any running processes on port 80.
/etc/init
or /etc/init.d
.Use $ mup logs -f
to view mup logs. To view errors from your app, the end of the file, /var/log/upstart/your_app.log
is useful (assuming you have upstart configured).
If using nginx make sure your directories are symlinked.
$ ln -s /etc/nginx/sites-available/your_server_config /etc/nginx/sites-enabled/your_server_config
Moreover, make sure that you have specified a default_server
5 in your_server_config
.
Check that mongodb can run.
Meteor version 1.0.4.1 (released near the end of March 2015) requires that node version 0.10.36 be installed. I recommend using the node version manager, n, to control what version of node is running on your server at any one time. Link.
The dreaded [XXX.XX.XXX.XX] Error: '/opt/your_app/programs/server/node_modules/fibers/bin/linux-x64-v8-3.28/fibers.node' is missing. Try reinstalling 'node-fibers'?
error. Link.
The procedure is modified from here: Link.
For your information, I used DigitalOcean's very helpful guide on deploying a meteor app to a server. Link.
Specifying a default_server
. Link.
Common processes to restart are: sudo service mongod/nginx/yourapp restart
.
I had the exact same issue - I switched to using Meteor Up (MUP) instead and the problem went away. Not to mention its a lot more straightforward!
I followed this tutorial on youtube - https://www.youtube.com/watch?v=WLGdXtZMmiI which covers deploying using MUP to Digital Ocean.
MUP's github page specifically mentions that it handles binary NPM modules - https://github.com/arunoda/meteor-up#binary-npm-module-support
Hope that's some help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With