如何解决帕格中的[意外的令牌“缩进”]错误?

时间:2019-04-16 05:29:49

标签: pug

Error: /home/user/Desktop/app/backend/views/register.pug:2:1
    1|  doctype html
  > 2|  html
-------^
    3|    head
    4|      title = title
    5|    body

unexpected token "indent"
    at makeError (/home/user/Desktop/app/backend/node_modules/pug-error/index.js:32:13)
    at Parser.error (/home/user/Desktop/app/backend/node_modules/pug-parser/index.js:53:15)
    at Parser.parseExpr (/home/user/Desktop/app/backend/node_modules/pug-parser/index.js:264:14)
    at Parser.parse (/home/user/Desktop/app/backend/node_modules/pug-parser/index.js:112:25)
    at parse (/home/user/Desktop/app/backend/node_modules/pug-parser/index.js:12:20)
    at Object.parse (/home/user/Desktop/app/backend/node_modules/pug/lib/index.js:125:22)
    at Function.loadString [as string] (/home/user/Desktop/app/backend/node_modules/pug-load/index.js:45:21)
    at compileBody (/home/user/Desktop/app/backend/node_modules/pug/lib/index.js:86:18)
    at Object.exports.compile (/home/user/Desktop/app/backend/node_modules/pug/lib/index.js:242:16)
    at handleTemplateCache (/home/user/Desktop/app/backend/node_modules/pug/lib/index.js:215:25)
    at Object.exports.renderFile (/home/user/Desktop/app/backend/node_modules/pug/lib/index.js:427:10)
    at Object.exports.renderFile (/home/shivtaj/Desktop/app/backend/node_modules/pug/lib/index.js:417:21)
    at View.exports.__express [as engine] (/home/user/Desktop/app/backend/node_modules/pug/lib/index.js:464:11)
    at View.render (/home/user/Desktop/app/backend/node_modules/express/lib/view.js:135:8)
    at tryRender (/home/user/Desktop/app/backend/node_modules/express/lib/application.js:640:10)
    at Function.render (/home/user/Desktop/app/backend/node_modules/express/lib/application.js:592:3)

1 个答案:

答案 0 :(得分:0)

帕格对压痕非常敏感。上面的错误消息表明您在html标记前面有一个空格字符,但不是这样。

doctype htmlhtml行移到最左边,因此它们前面没有空格。然后,确保其他行正确缩进(要缩进两个空格),否则您将在其余行上看到缩进错误。