2013-03-14 54 views
0

我發現了一個Error: cannot find module 'hogan'當我發送給在這裏的CoffeeScript實現Node.js的服務器發出請求:快遞+整合+霍根:'錯誤:無法找到模塊「法眼」`與代碼直接從鞏固文檔

https://gist.github.com/wmayner/306c89d7f8fbeed3f098

我已經安裝了依賴關係hogan.js,consolidateexpress

我已經從consolidate的文檔(轉載如下)幾乎完全轉載了示例代碼,所以我無法查看此錯誤來自哪裏。它看起來應該起作用。

consolidate docs

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

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

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

我也嘗試宣告`霍根=需要( 'hogan.js')」作爲一個依賴。

任何人都有一個想法,爲什麼發生這種情況?


注:要點上面從consolidate文檔不同之處在於我設置view enginehogan,而不是html。這是因爲我寧願使用.hogan而不是.html作爲我的模板文件擴展名(我試過.html,我得到相同的錯誤)。

回答

1

你要點設置hoganview engine,但應該是html像合併文檔:

// tell Express to use Consolidates 'hogan' renderer for .html templates 
engines = require 'consolidate' 
engine = 'hogan' 
app.engine 'html', engines[engine] 

// tell Express to use '.html' as extension to find views with .render() 
app.set 'view engine', 'html' 

編輯:意識到,也許你想使用.hogan爲擴展名的模板文件,你可以用這個代替:

app.engine 'hogan', engines[engine] 
app.set 'view engine', 'hogan' 
+0

但引擎是'hogan'',所以這實際上是我已經試過的要點'app.engine'html',引擎[引擎] \ app.set'視圖引擎',引擎(我確實希望使用'.hogan'而不是'.html')。 – Will 2013-03-14 13:43:36

+0

試試這個要點:https://gist.github.com/robertklep/5161641 – robertklep 2013-03-14 14:16:35

+0

完美!謝謝。我沒有意識到'app.engine'的第一個參數也是模板的文件擴展名,我沒有注意到你在編輯中將它改爲'hogan' - 只看到了第二行。我的錯! – Will 2013-03-14 15:33:14