2013-03-13 9 views
7

Ich versuche Consolidate mit Knoten (Express v3.1.0) zu installieren, Swig zu verwenden. Ich halte den Fehler immerNode.JS Consolidate und Swig

Error: Cannot find module 'swig' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Function.exports.swig.render (/home/jamie/node_modules/consolidate/lib/consolidate.js:237:50) at /home/jamie/node_modules/consolidate/lib/consolidate.js:144:25 at /home/jamie/node_modules/consolidate/lib/consolidate.js:97:5 at fs.readFile (fs.js:176:14) at Object.oncomplete (fs.js:297:15)

An der Spitze, habe ich es auf ähnliche

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'); 

dann ich meine Anfrage wie folgt machen:

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

ich eine Vorlage haben, nach Hause .html, im Stammverzeichnis/Ansichten

Mein Stammverzeichnis ist/home/jamie/hallo-world. Was mache ich hier falsch?

Bearbeiten Übrigens gibt die console.log (cons.swig) etwas zurück. So

{ [Function] render: [Function] } 

seine definitiv dort

Antwort

11

Haben installieren Sie das swig Paket? Von der Readme:

NOTE: you must still install the engines you wish to use, add them to your package.json dependencies.

+1

DAS ist, was ich vermisst wurde. Ich hatte swig installiert, nur nicht zum package.json hinzugefügt. Danke, dass du das gezeigt hast !! – Jameo

+0

@Jameo Ich bin froh, dass ich helfen konnte. –