2015-10-18 53 views
4

我试图将我的应用程序投入Sails.js的生产环境,但无法通过繁重的任务。这是我收到的错误:无法将Sails.js应用程序投入生产

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) 

我有大幅提升sails.config.grunt._hookTimeout仍然过程尚未完成。在生产或开发的输出运行sails debug

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 

我觉得很奇怪,在开发模式下,一切工作正常,但它不是在生产的情况。包含的文件非常大,如角度,时刻和其他模块。这是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' 

]; 

我不知道还有什么会导致此,有什么建议?我使用的版本扬帆0.11.0

+0

您使用什么端口进行生产?如果它是80端口,看看是否有其他服务使用它(nginx,apache等)并杀死它们。同样值得尝试以root身份提升sails以查找它是否与权限相关。 – galactocalypse

+0

我以root身份运行,并在端口443上运行SSL。无论如何,它仍然无法使用80。没有安装apache或nginx。 –

+0

尝试运行grunt uglify:dist本身 – joncodo

回答

4

我只是有这个同样的问题,它只是超时是不够大,我不得不把这个在我的配置/ local.js文件:

module.exports = { 
    hookTimeout: 120000 
}; 
+0

在一年后回到这里,我会说你应该运行带有--verbose标志的grunt或grunt buildProd看看为什么这需要很长时间才能运行。也可能是其他的东西已经在那个端口上运行了。你可以做一个帆升降机--port = 1234在另一个港口进行测试 – joncodo

1

我刚刚在github上发布了相同的问题,然后检出了源代码。所以我通过咕噜声来了解发生了什么。事实证明,在default模式下,grunt挂钩在grunt启动后立即触发回调,但对于prod模式,只有在grunt完成所有任务后才会触发。

有一个在源代码如下评论:

CB - 可选,火灾时,繁重的任务已经启动(非生产)或成品(生产)

所以,如果在prod中有任何正在观看的东西(例如在browserify中使用watch),grunt任务将永远不会退出,因此grunt钩子将始终超时。但即使没有什么东西在看,开始咕噜的任务需要更长的时间才能完成所有的任务,这就解释了为什么我们不在生产模式下看不到问题。 由于修改原始grunt钩子并不是最好的主意(它生活在node_modules),所以最好的做法是增加(可能显着)_hookTimeout选项并确保grunt任务退出(为此可以与grunt prod分开运行) 。