2017-11-21 22 views
1

小さなコンテンツを出力する単純なアプリケーションがあります。私はNodeJs、ExpressとPugを使用します。Pugテンプレートを使用すると予期しないトークン "インデント"

const pug = require('pug'); 
const express = require('express'); 
const app = express(); 

const indexFile = 'index'; // the file to load 

app.set('view engine', 'pug'); // use pug 

app.get('/', function (req, res) { 
    res.render(indexFile, {content: 7}); // load the file and set the variable to 7 
}); 

app.listen(8888, function() { 
    console.log('Server running on port 8888'); 
}); 

そして、私のパグファイル/ HTML

doctype html 
    link(rel='stylesheet', href='../CSS/requirements.css') 
    script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js') 
    body 
     p = content 

サーバーを起動する私は、このエラーメッセージ

Error: C:\Users\mah\Desktop\Test\views\index.pug:2:1 
    1| doctype html 

    > 2|  link(rel='stylesheet', href='../CSS/requirements.css') 

-------^ 
    3|  script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js') 

    4|  body 

    5|  p = content 


unexpected token "indent" 
    at makeError (C:\Users\mah\Desktop\Test\node_modules\pug-error\index.js:32:13) 
    at Parser.error (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:53:15) 
    at Parser.parseExpr (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:264:14) 
    at Parser.parse (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:112:25) 
    at parse (C:\Users\mah\Desktop\Test\node_modules\pug-parser\index.js:12:20) 
    at Object.parse (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:126:22) 
    at Function.loadString [as string] (C:\Users\mah\Desktop\Test\node_modules\pug-load\index.js:45:21) 
    at compileBody (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:86:18) 
    at Object.exports.compile (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:243:16) 
    at handleTemplateCache (C:\Users\mah\Desktop\Test\node_modules\pug\lib\index.js:216:25) 

を受け取る誰かがここに私を助けてもらえますか?

答えて

2

doctype htmlの直後にhtmlを忘れてしまったと思います。

doctype html 
html 
    link(rel='stylesheet', href='../CSS/requirements.css') 
    script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js') 
    body 
    p=content 

doctype htmlhtmlは同じ意図レベルであるべきです。 Btw、p = contentp=contentに変更して渡された値を印刷

+0

はい、これは正しいものでした – peterHasemann

関連する問題