Omar Mir
Omar Mir

Reputation: 1624

Including pug file causes error but jade works fine

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.

Upvotes: 4

Views: 2624

Answers (2)

Haroen Viaene
Haroen Viaene

Reputation: 1360

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.

Upvotes: 0

Omar Mir
Omar Mir

Reputation: 1624

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.

Upvotes: 4

Related Questions