Node Express合并Hogan - 编译部分时出现不一致的错误

时间:2014-06-25 08:57:24

标签: node.js express hogan.js

我将我的应用程序从较旧的库更新到最新的库但我遇到了不一致的错误 我的文章:

npm list --depth=0
    ├── consolidate@0.10.0
    ├── express@4.4.4
    ├── hogan.js@3.0.2
    ├── node-uuid@1.4.1
    └── socket.io@1.0.6

以下是我运行的代码示例。完整代码here

var express = require('express');
var http = require('http');
var uuid = require('node-uuid');
var consolidate = require('consolidate');

//////////////////////
// Server setup
//////////////////////
var app = express();
app.engine('html', consolidate.hogan);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.enable('view cache');
app.disable('view layout');

var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.set('log level', 1); // reduce logging

server.listen(9000);

//////////////////////
// Routing
//////////////////////
// Partials used in many rendering views
function hoganPartials() {
    return {
        head : 'common/head',
        mainHeader : 'common/mainHeader',
        mainFooter : 'common/mainFooter'
    };
};

app.use('/files', express.static(__dirname + '/files'));

app.get('/about', function(req, res) {
    res.render('about', {
        partials: hoganPartials(),
        title : 'Title - About'
    });
});

因此,当我运行此代码时,我有时会一个随机错误:

  • 如果页面首次正确呈现,即使刷新后也会始终正确呈现。
  • 如果页面无法使用 error1 呈现,则每次刷新时,都将无法使用 error2 呈现。
  • 某些视图可能会呈现,而其他视图则不会呈现相同的部分视图。
  • 重新启动应用程序将重置错误,并且上一次运行中的某些视图失败可能会在当前版本中运行,反之亦然。
  • 禁用视图缓存没有任何影响。

错误1

SyntaxError: Unexpected token ( at Object.Function (<anonymous>) 
    at Object.Hogan.makePartials (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:301:28) 
    at Object.Hogan.makeTemplate (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:290:25) 
    at Object.Hogan.generate (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:280:17) 
    at Object.Hogan.compile (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:416:21) 
    at Function.exports.hogan.render (/home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:448:56) 
    at /home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:144:25 
    at /home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:97:5 
    at fs.js:271:14 
    at Object.oncomplete (fs.js:107:15)

错误2

SyntaxError: Unexpected token ( at Object.Function (<anonymous>) 
    at Object.Hogan.makePartials (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:301:28) 
    at Object.Hogan.makeTemplate (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:290:25) 
    at Object.Hogan.generate (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:280:17) 
    at Object.Hogan.compile (/home/philaeux/dota2draft/node_modules/hogan.js/lib/compiler.js:416:21) 
    at Function.exports.hogan.render (/home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:448:56) 
    at /home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:144:25 
    at read (/home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:91:22) 
    at /home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:142:9 
    at next (/home/philaeux/dota2draft/node_modules/consolidate/lib/consolidate.js:117:38)

我试图降级一些libs但没有成功。我无法记住我从哪个版本开始(可能表达&lt; 4.0.0)。我完全迷失在这一个...... 谢谢你的时间。

0 个答案:

没有答案