无法将Sails.js应用程序投入生产

问题描述 投票:5回答:2

我正在尝试使用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'

];

我不知道还有什么会导致这个,有什么建议吗? 我正在使用Sails版本0.11.0

node.js gruntjs sails.js
2个回答
6
投票

我只是遇到了同样的问题而且只是超时不够大我必须将它放在我的config / local.js文件中:

module.exports = {
    hookTimeout: 120000
};

1
投票

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

源代码中有以下注释:

cb - 可选,在Grunt任务启动(非生产)或完成(生产)时触发

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

© www.soinside.com 2019 - 2024. All rights reserved.