4

Running into a weird issue here. I have a pretty basic jade/pug include going on here:

extends base.pug

block vars
    - var title = 'Home'

block body
    header
        include ./includes/header.pug

A quick note, just using extends base (without the extension) just doesn't work. But this include gives the following error:

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)

But changing that to :

extends base.pug

block vars
    - var title = 'Home'

block body
    header
        include ./includes/header.jade

Works perfectly fine. The contents of header.jade and header.pug are the exact same so I am a bit perplexed here. Some help would be appreciated.

Thanks,

PS: Searching did reveal: https://github.com/pugjs/pug-linker/issues/13 - seems to be a bug but not sure how this could be.

Omar Mir
  • 1,500
  • 1
  • 19
  • 39
  • 1
    This works for me now. If you are still having issue, check out https://github.com/pugjs/pug/issues/2305 to see if it's related to any of that as well. – Jason Lydon May 04 '16 at 14:36

2 Answers2

4

So it looks like pug isn't really ready for primetime YET! Look forward to when it is but using jade instead of pug solves the issue, just rename everything to .jade.

Omar Mir
  • 1,500
  • 1
  • 19
  • 39
0

One of the breaking changes in the move from Jade to Pug is that you can't interpolate variables anymore. You used to be able (and encouraged) to use #{something} inside another string, but now you're encouraged to use regular JavaScript variables.

for example, this

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

should now become

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

Source: tracking issue with breaking changes.

Haroen Viaene
  • 1,329
  • 18
  • 33