Node.js 无法将Sails.js应用程序投入生产
我正试图使用Sails.js将我的应用程序投入生产,但无法通过繁重的任务。这是我收到的错误:Node.js 无法将Sails.js应用程序投入生产,node.js,gruntjs,sails.js,Node.js,Gruntjs,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 too
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.\u hookTimeout
,但这个过程仍然没有完成。在生产或开发输出中运行sail 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我也遇到了同样的问题,只是超时不够大,我不得不将其放入我的config/local.js文件中:
module.exports = {
hookTimeout: 120000
};
我刚刚在github上发布了同样的问题,然后查看了源代码。所以我通读了grunt钩子来了解发生了什么。事实证明,在
default
模式下,grunt钩子会在grunt启动后立即触发回调,但在prod
模式下,只有在grunt完成所有任务时才会触发回调
源代码中有以下注释:
cb-可选,在Grunt任务启动(非生产)或完成(生产)时激发
因此,如果在prod
中有任何正在监视的内容(如在browserify中使用watch
),grunt任务将永远不会退出,因此grunt钩子将始终超时。但是,即使没有人观看,启动grunt任务也比完成所有任务花费更长的时间,这就解释了为什么我们在不处于生产模式时看不到问题。
由于修改原始的grunt钩子不是最好的主意(它存在于
节点\u模块中
),因此最好的办法是增加\u钩子超时
选项,并确保grunt任务退出(为此,可以使用grunt prod
单独运行)。您在生产中使用的端口是什么?如果是端口80,请查看是否有其他服务已经在使用它(nginx、apache等),并杀死它们。同样值得尝试以root身份提升sail,以发现这是否是一个与权限相关的问题。我以root身份运行,并在SSL的端口443上运行它。尽管它在80上没用。没有安装apache或nginx。请尝试自行运行grunt uglify:dist尝试在端口1337中运行它,可能您已经在使用默认端口。一年后,我会说您应该使用--verbose标志运行grunt或grunt buildProd,以了解为什么运行这么长时间。也可能是该端口上已在运行其他内容。您可以在另一个端口上进行sails lift--port=1234测试