queckezz/koa-views

Render() failed when given a directory and using non-HTML extension

gnituy18 opened this issue · 5 comments

I use pug as my default extension for my views.
And I structure my views dir like this:

views/dirA/index.pug
views/dirA/_include.pug
views/dirB/index.pug
app.use(views(__dirname + '/views', {'extension': 'pug'}))

app.use(async function (ctx) {
  await ctx.render('dirA')
})

I want to render dirA/index.pug just by passing dirA , but I got a error like this:

Error: ENOENT: no such file or directory, open '/blah/blah/blah/app/views/dirA/dirA/index.pug'
at Object.fs.openSync (fs.js:582:18)
      ........
      ........
      ........
at /blah/blah/blah/app/node_modules/koa-views/lib/index.js:53:20

Without the extension, everything works fine.
So when I go further... I think that

// koa-views/src/index.js:64
abs: join(abs, dirname(rel), rel),

is what causes .../views/dirA/dirA/index.pug got 2 dirA

// koa-views/src/index.js:46
return render(resolve(paths.abs, paths.rel), state)

Hi, do you use the latest version ?

Yes. I'm using 6.0.0

Hi, I think cfe2202 fixes the BUG

But I have no permission for npm publishing, please wait for @queckezz

Thanks for the fast fix! @int64ago. You should now be able to publish new versions ✨

image

@queckezz Thx :-)

@gnituy18 Now, you can check v6.0.1, thanks for your patience