queckezz/koa-views

ctx.render is not a function

Closed this issue · 4 comments

// dependencies
import Koa from 'koa';
import jade from 'jade';
import path from 'path';

// middleware dependencies
import Router from 'koa-router';
import views from 'koa-views';
import convert from 'koa-convert';

// init
const app = new Koa();
const router = new Router();

// middlewares
app.use(convert(views(__dirname + '/views', { extension: 'jade' })));
app.use(convert(router.routes())).use(convert(router.allowedMethods()));

// routes
router.get('/', async function (ctx, next) {
  await ctx.render('index');
});

// start app
app.listen(8080);
export default app;

What's wrong with this code? I tried different versions, but always get TypeError...

Can you add a failing test? Also if you are using koa@2 you can use koa-views@5 as described in the readme instead of koa-convert.

npm install koa-views@next

Where do i need to write tests? It's all code what i have (excluding babel presets/polyfills).
I used both koa v2 + koa-views && koa v2 + koa-views@next... same result.
And sorry, but i really bad in writing tests.... near to zero. 😢

Your example code works just fine for me. Check out https://github.com/queckezz/koa-views-issue-57. Hopefully this helps!

hmm.. it works 😮
very weird.... anyway, it's my fault. Thanks for example! 👍