2017-06-10 42 views
0

誰能告訴我爲什麼哈巴狗API不具有簡單的例子,從他們的文檔頁面帕格API不工作

const pug = require('pug'); 

// Compile the source code 
const compiledFunction = pug.compileFile('template.pug'); 

// Render a set of data 
console.log(compiledFunction({ 
    name: 'Timothy' 
})); 
// "<p>Timothy's Pug source code!</p>" 

工作沒有梅特我做什麼它總是告訴pug.compileFile不是一個函數

回答

0

給定的代碼對我來說工作得很好。這是我做的一個Glitch instance測試。請注意,控制檯正確註銷了template.pug模板中的已編譯HTML。

說了這麼多,請確保你已經做了正確的以下內容:

  • 安裝哈巴狗和它保存到您的package.json:npm install pug --save
  • 有一個有效的template.pug文件在正確的位置

看看Glitch實例,你可能會發現問題所在。