2012-05-24 92 views
4

快速問題:爲什麼express.js不能運行dust.js?
我知道這不是官方支持,但dust.js甚至有我的node.js版本的問題。
由於require.path問題,節點甚至不會啓動。node.js + express.js + dust.js問題

server:testapp treejanitor$ node --version 
v0.6.12 

將應用程序引擎設置爲灰塵時出現問題。 (快遞app.js

var dust = require('dust'); 
... 
app.set('view engine', 'dust'); 

我表示儲物這裏給你我的簡單的模塊列表。
也有人搜索相同的問題可能會剪切/粘貼錯誤。

server:hummr treejanitor$ npm list 
[email protected] /Users/treejanitor/git/testapp/testapp 
├── [email protected] extraneous 
├── [email protected] 
├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
└─┬ [email protected] 
    ├── [email protected] 
    └── [email protected] 

server:testapp treejanitor$ supervisor app.js 

DEBUG: Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead. 
    at Function.<anonymous> (module.js:378:11) 
    at Object.<anonymous> (/Users/treejanitor/git/testapp/testapp/node_modules/dust/lib/server.js:6:8) 

我試過,沒有運氣以下嘗試:
Dust.js load template from filesystem in Node.js

注:我試過快遞(3.0),這並沒有幫助的alpha版本。
solidate.js和example中的所有模塊也是如此。


爲什麼我感興趣的節點+快遞+防塵一些原因:
LinkedIn picks dustjs
Twitter's Bootstrap framework

回答

2

因此,這裏的竅門 - 我想我會分享我發現了什麼。
它需要找到這個塊 - 如果你有興趣,可以在頁面中搜索dust-x。 http://nodejs.debuggable.com/2012-03-23.txt

要解決的事情,在你的快遞應用

cd node_modules 
git clone git://github.com/laurie71/dust-x.git 
git clone https://github.com/caolan/dustjs.git 

dust.js解決與node.js的
https://github.com/caolan/dustjs

粉塵的 '包裝' 的require.paths問題的叉子使其成爲模板引擎
(您仍然需要將dust.js作爲模塊安裝)
https://github.com/laurie71/dust-x

的例子使用
https://gist.github.com/2174537

最重要的一點:

var dustx = require('dust-x'); 

... 

// Configuration 

app.configure(function(){ 
    app.set('views', __dirname + '/views'); 
    app.register('.dust', dustx/*({})*/); 
    app.set('view engine', 'dust'); 
    // app.set('view engine', 'jade'); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(app.router); 
    app.use(express['static'](__dirname + '/public')); 
}); 

順便說一句,我認爲我可以手動固定其server.js內dust.js問題,但我想給榮譽給那些真正分叉dust.js的人,並且公開提供瞭解決方案。


PS:我仍然是相當新的張貼計算器,所以如果我違反了一些禮儀只是讓我知道。我在FAQ中讀到,鼓勵回答你自己的問題,所以我想我會試試看。

特別是,我知道我的格式可能很弱。在答案中,我實際上首選顯示完整鏈接,而不是指導建議的網址嵌入,因爲它揭示了包含網站的結構。隨着網站URL吸收到你的大腦中,它給了你更多的機會參考下一個複製。此外,這些網址相當短。 ; ^)建議非常感謝

「控制檯」通常被格式化的方式是什麼?作爲代碼?

2

它可能是一個與node.js和express.js版本的問題..我使用節點v0.10.9和表達v3.0.x,他們適合我。 對於express.js和node.js的整合dust.js,我發現這個GitHub庫是一個有用的資源,以幫助您開始使用: https://github.com/chovy/express-template-demo (它使用dust.js的LinkedIn叉)