Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to put Sails.js app in production

I'm trying to put my app into production with Sails.js, but cannot get past the grunt tasks. This is the error I'm receiving:

error: Error: The hook `grunt` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set 
`sails.config.grunt._hookTimeout to a higher value (currently 20000)
at tooLong [as _onTimeout] 
   (/usr/local/lib/node_modules/sails/lib/app/private/loadHooks.js:92:21)
   at Timer.listOnTimeout (timers.js:110:15)

I have increased sails.config.grunt._hookTimeout dramatically and still the process hasn't been completed. Running a sails debug in either production or development outputs:

Grunt :: Error: listen EADDRINUSE
   at exports._errnoException (util.js:746:11)
   at Agent.Server._listen2 (net.js:1156:14)
   at listen (net.js:1182:10)
   at Agent.Server.listen (net.js:1267:5)
   at Object.start (_debugger_agent.js:20:9)
   at startup (node.js:86:9)
   at node.js:814:3

I find it very strange that in development mode everything works fine, but its not the case in production. The files included are pretty big, such as angular, moment and other modules. This is how the jsFilesToInject looks:

var jsFilesToInject = [

 // Load sails.io before everything else
 'js/dependencies/sails.io.js',

 'js/dependencies/angular.min.js',
 'js/dependencies/moment.min.js',
 'js/dependencies/angular-ui-router.min.js',
 'js/dependencies/angular-sails.min.js',
 'js/dependencies/angular-moment.min.js',
 'js/dependencies/angular-animate.min.js',
 'js/dependencies/angular-aria.min.js',
 'js/dependencies/angular-material.min.js',

 // All of the rest of your client-side js files
 // will be injected here in no particular order.
 'js/**/*.js'

];

I'm not sure what else would be causing this, any suggestions? I'm using Sails version 0.11.0

like image 319
Michael Wilson Avatar asked Oct 18 '15 15:10

Michael Wilson


People also ask

How do I run sails JS app?

Lift your app As you can see, instead of sails lift you should start your Sails app with node app. js in production. This way, instead of relying on having access to the sails command-line tool, your app just runs the app. js file bundled in your Sails app (which does the same thing).

How do I change the port on my sails?

So you can use: sails lift to run your app on the default port (1337 if you don't modify your config) sails console --port 1338 in an other tab/window to run the console on another port.

Is sails JS framework?

Sails is the most popular MVC framework for Node. js, designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with a scalable, service-oriented architecture.


2 Answers

I just had this same problem and it was just that the timeout was not big enough I had to put this in my config/local.js file:

module.exports = {
    hookTimeout: 120000
};
like image 179
joncodo Avatar answered Oct 21 '22 20:10

joncodo


I just posted the same issue on github, and then checked out the source code. So I read through the grunt hook to understand what happens. And it turns out that in default mode the grunt hook triggers the callback right after grunt has started, but for the prod mode it is triggered only when grunt has finished all the tasks.

There is a following comment in the source code:

cb - optional, fires when the Grunt task has been started (non-production) or finished (production)

So if there is anything watching (like using watch in browserify) in prod, grunt task will never exit, and therefore grunt hook will always timeout. But even if nothing is watching, starting the grunt task takes much longer that finishing all the tasks, and this explains why we don't see the problem when not in production mode. Since modifying the original grunt hook is not the best idea (it lives in node_modules), the best is indeed to increase (possibly dramatically) the _hookTimeout option and to make sure grunt task exits (for this it can be run separately with grunt prod).

like image 29
amberv Avatar answered Oct 21 '22 20:10

amberv