fastify / point-of-view

Template rendering plugin for Fastify
MIT License
344 stars 87 forks source link

Path resolved from path.join gives 'ENOENT: no such file or director' Error. #298

Closed jungRoit closed 2 years ago

jungRoit commented 2 years ago

Prerequisites

Fastify version

3.27.2

Plugin version

5.1.0

Node.js version

14.18.2

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

MacOS Big Sur v11.6.4

Description

I use path.join to convert my relative path to absolute path for the pug file. When giving the relative path the template is rendered but when I give the file path that I joined using path.join I get ENOENT: no such file or directory error.

I tried setting root to / and baseDir to / but still got the same result.

Here's my plugin file: module.exports = fp(async function (fastify, opts) { fastify.register(pointOfView, { engine: { pug: require('pug'), }, }); })

here's how I create the path and send it to the reply.view function: const errorWidgetPath = path.join(__dirname, '../views/web/error.pug'); ... reply.view(errorWidgetPath, props);

Steps to Reproduce

  1. Add Point-of-view as a plugin and use pug as engine.
  2. create a path using path.join() function. // const errorWidgetPath = path.join(__dirname, '../views/web/error.pug');
  3. render tha file from the path using reply.view // reply.view(errorWidgetPath, props);

Expected Behavior

The template should be rendered.