【问题标题】:Including pug file causes error but jade works fine包括哈巴狗文件会导致错误,但玉工作正常
【发布时间】:2016-08-21 04:36:53
【问题描述】:

在这里遇到了一个奇怪的问题。我有一个非常基本的玉/哈巴狗包括在这里:

extends base.pug

block vars
    - var title = 'Home'

block body
    header
        include ./includes/header.pug

快速说明,仅使用 extends base(不带扩展名)是行不通的。但是这个包含给出了以下错误:

TypeError: Cannot read property 'replace' of undefined
   at before (/var/node/website/node_modules/pug-linker/index.js:104:48)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:13:26)
   at /var/node/website/node_modules/pug-walk/index.js:21:16
   at Array.map (native)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:20:29)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:33:21)
   at /var/node/website/node_modules/pug-walk/index.js:21:16
   at Array.map (native)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:20:29)
   at /var/node/website/node_modules/pug-walk/index.js:21:16
   at Array.map (native)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:20:29)
   at applyIncludes (/var/node/website/node_modules/pug-linker/index.js:102:10)
   at link (/var/node/website/node_modules/pug-linker/index.js:21:9)
   at compileBody (/var/node/website/node_modules/pug/lib/index.js:84:11)
   at Object.exports.compile (/var/node/website/node_modules/pug/lib/index.js:164:16)

但将其更改为:

extends base.pug

block vars
    - var title = 'Home'

block body
    header
        include ./includes/header.jade

工作得很好。 header.jade 和 header.pug 的内容完全一样,所以我在这里有点困惑。一些帮助将不胜感激。

谢谢,

PS:搜索确实显示:https://github.com/pugjs/pug-linker/issues/13 - 似乎是一个错误,但不确定这是怎么回事。

【问题讨论】:

标签: node.js express pug pugjs


【解决方案1】:

所以看起来哈巴狗还没有准备好迎接黄金时段!期待什么时候,但是使用jade代替pug可以解决问题,只需将所有内容重命名为.jade

【讨论】:

    【解决方案2】:

    从 Jade 迁移到 Pug 的一个重大变化是您不能再对变量进行插值。您曾经能够(并鼓励)在另一个字符串中使用 #{something},但现在我们鼓励您使用常规 JavaScript 变量。

    比如这个

    a(href="#{link}")
    a(href='before#{link}after')
    

    现在应该变成

    a(href=link)
    a(href=`before${link}after`) //(on Node.js/io.js ≥ 1.0.0)
    a(href='before' + link + 'after') //(everywhere)
    

    来源:跟踪 issue 并进行重大更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      • 1970-01-01
      • 2017-07-13
      • 2017-06-27
      • 2018-09-15
      • 2018-05-13
      相关资源
      最近更新 更多