Failed to add Sails.js application to production.

I am trying to put my application into production using Sails.js, but I can not get past the grunt tasks. This is the error I get:

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 drastically increased sails.config.grunt._hookTimeout and the process is still not complete. Running sails debug in product or development output:

 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 

It is very strange to me that in development mode everything works fine, but not in production. The attached files are quite large, for example angular, moment and other modules. This is what jsFilesToInject looks jsFilesToInject :

 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 could cause this, any suggestions? I am using Sails version 0.11.0

+5
source share
2 answers

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

 module.exports = { hookTimeout: 120000 }; 
+6
source

I just posted the same issue on github and then checked the source code. So I read grunts to understand what is happening. And it turns out that in default mode, the grunted hook starts a callback immediately after the start of grunt, but for prod mode it starts only when grunt has completed all the tasks.

There is the following comment in the source code:

cb - optional, triggered when a Grunt task is started (non-production) or completed (production)

So, if there is anything looking (for example, using watch in the browser) in prod , the grunt task will never exit, and therefore the grunt hook will always time out. But even if nothing is observed, starting a grunt task takes much longer, completing all tasks, and this explains why we do not see a problem when not in production mode. Since modifying the original hook for the grunt is not a good idea (it lives in node_modules ), it’s best to really increase (possibly abruptly) the _hookTimeout parameter and make sure the grunt task comes out (for this you can run it separately with grunt prod ).

+1
source

Source: https://habr.com/ru/post/1233971/


All Articles