【问题标题】:Node.JS Consolidate and SwigNode.JS 整合和 Swig
【发布时间】:2013-02-28 18:11:22
【问题描述】:

我正在尝试设置 Consolidate with node(express v3.1.0),以使用 Swig。我不断收到错误

错误:找不到模块“swig” 在 Function.Module._resolveFilename (module.js:338:15) 在 Function.Module._load (module.js:280:25) 在 Module.require (module.js:362:17) 在需要(module.js:378:17) 在 Function.exports.swig.render (/home/jamie/node_modules/consolidate/lib/consolidate.js:237:50) 在 /home/jamie/node_modules/consolidate/lib/consolidate.js:144:25 在/home/jamie/node_modules/consolidate/lib/consolidate.js:97:5 在 fs.readFile (fs.js:176:14) 在 Object.oncomplete (fs.js:297:15)

在顶部,我是这样设置的

var express = require('express');
var cons = require('consolidate');

// assign the swig engine to .html files
console.log(cons.swig);
app.engine('html', cons.swig);

// set .html as the default extension 
app.set('view engine', 'html');
app.set('views', __dirname + '/views');

然后我提出这样的要求:

app.get('/', function(req, res){
    res.render('home', {
        title: "home"
    });
});

我在根目录/views 中有一个模板 home.html

我的根目录是/home/jamie/hello-world。我在这里做错了什么?

编辑 顺便说一句,console.log(cons.swig) 确实返回了一些东西。

{ [Function] render: [Function] }

所以它肯定那里

【问题讨论】:

    标签: node.js express swig-template


    【解决方案1】:

    您是否安装了swig 软件包?来自自述文件:

    注意:您仍然必须安装您希望使用的引擎,将它们添加到您的 package.json 依赖项中。

    【讨论】:

    • 这就是我所缺少的。我已经安装了 swig,只是没有添加到 package.json 中。感谢您指出这一点!
    猜你喜欢
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    相关资源
    最近更新 更多