Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.render is not a function #18

Closed
uptownhr opened this issue May 6, 2016 · 5 comments
Closed

this.render is not a function #18

uptownhr opened this issue May 6, 2016 · 5 comments

Comments

@uptownhr
Copy link

uptownhr commented May 6, 2016

I'm using koa@2 and getting _this.render is not a function

this.render('index')

Doing ctx.render does work but I need to specify 'index.pug' and not just 'index'. Also, not if it is related but string interpolation no longer works.

p.text-xs-center $ #{product.price}

Just outputs #{product.price} after it's converted to html.

package.json
{
  "koa": "^2.0.0",
  "koa-pug": "^3.0.0-0"
}
@chrisyip
Copy link
Owner

chrisyip commented May 7, 2016

koa-pug is not fully support koa@2 yet, though it can work.

  1. koa@2 uses ctx instead of this for context of one request, please use ctx.render instead: https://github.com/koajs/koa/tree/v2.x#old-signature-middleware-v1x---deprecated .
  2. About .pug extname and string interpolation, can you post your codes? I can't reproduce these issues.

@uptownhr
Copy link
Author

uptownhr commented May 9, 2016

I must have been doing something dumb, I'm not able to reproduce the .pug extension error anymore. I just tried again and removed the .pug on render and it is working.

Regarding the interpolation, maybe something changed with the new version of pug than what I was using before. Basically, it still works but with the exception of one scenario.

So I have,
p.text-xs-center $ #{product.price}
and
p(data-test="#{product.name}")

The first scenario works fine but is the second that used to work but is not anymore. Ofcourse, I was able to fix this easily by removing the interpolation as it is not needed in this scenario. However, previously, I was able to use the #{} synthax inside quotes and get access to variables.

@uptownhr
Copy link
Author

uptownhr commented May 9, 2016

input(type="hidden", name="id", value=product._id)

I'm also seeing that my mongoose _id is being translated to, "572a5caab192c83000684413" From here, it seems a bit clear that it is currently different from the standard jade library I used before with express. Do you happen to know what the configurations are to change these?

@uptownhr
Copy link
Author

so i actually was able to reproduce the .pug error. This occurs when including or extending using a relative path.

for example, include ../partials/flash will result in ENOENT: no such file or directory, open '/app/views/partials/flash'\n at /app/views/admin/layout.pug line 118

but include ../partials/flash.pug will work. Same thing with extends ../layout. You need to add .pug for this to work.

@chrisyip
Copy link
Owner

It is a bug of Pug, and fixed in alpha7: pugjs/pug@2d79b88 .

There're two solutions:

  • If you're using npm ^3.7, you can run npm i pug@2.0.0-alpha7
  • Reinstall koa-pug, npm will install latest Pug for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants