fastify / point-of-view

Template rendering plugin for Fastify
MIT License
343 stars 86 forks source link

nunjucks Cannot read property 'config' of undefined #311

Closed johntom closed 2 years ago

johntom commented 2 years ago

Prerequisites

Issue

node version 14.18.3 windows home 10 I'm tring to add nunjucks to a pre-existing repo. The folling package.json shows dependencies and versions 1) the following gets loaded from app/plugins/nunjucks.js

'use strict'
const fp = require('fastify-plugin')
const path = require('path')
const join = require('path').join;
module.exports = fp(async (fastify, opts) => {
    fastify.register(require("point-of-view"), {
        engine: {
            nunjucks: require('nunjucks'),                     
        },

        templates: path.resolve('../../../views/'),

    })

})

2) my test endpoint (http:127.0.0.1:9020/apihtmx/nunjucks/test) get loaded but. i get a slew of errors

fastify.get("/nunjucks/test", async (request, reply) => {
    reply.view('templates/index.html', { title: 'Test page', hello: 'world from greenport' });
  });
3)

Uncaught TypeError TypeError: Cannot read property 'config' of undefined
    at getRequestedPath (d:\devel\_Live\mongodonQBTest\node_modules\point-of-view\index.js:170:78)
    at <anonymous> (d:\devel\_Live\mongodonQBTest\node_modules\point-of-view\index.js:419:29)

Any pointers appreciated. John

package.json

 "dependencies": {
    "@google-cloud/storage": "^4.7.0",
    "@guivic/fastify-socket.io": "^0.1.1",
    "bcryptjs": "^2.4.3",
    "concat-stream": "^2.0.0",
    "csv-parser": "^1.11.0",
    "csvtojson": "^2.0.10",
    "dotenv": "^8.0.0",
    "ejs": "^3.1.8",
    "fastify": "^2.6.0",
    "fastify-autoload": "^1.0.0",
    "fastify-cli": "^1.1.0",
    "fastify-cookie": "^3.6.1",
    "fastify-cors": "^2.1.3",
    "fastify-favicon": "^2.0.0",
    "fastify-google-cloud-storage": "^1.0.1",
    "fastify-jwt": "^1.2.1",
    "fastify-mongodb": "^1.0.1",
    "fastify-multipart": "^1.0.1",
    "fastify-mysql": "^0.3.0",
    "fastify-plugin": "^1.6.0",
    "fastify-session": "^3.3.0",
    "fastify-swagger": "^2.4.0",
    "form-data": "^3.0.0",
    "fs-extra": "^8.1.0",
    "gm": "^1.23.1",
    "handlebars": "^4.7.6",
    "htmx.org": "^1.7.0",
    "imagemagick": "^0.1.3",
    "imagemagick-stream": "^4.1.1",
    "intuit-oauth": "^3.0.2",
    "lodash": "^4.17.15",
    "make-promises-safe": "^5.0.0",
    "moment": "^2.24.0",
    "node-quickbooks": "^2.0.37",
    "nodemon": "^1.19.4",
    "nunjucks": "^3.2.3",
    "pino-colada": "^1.4.5",
    "point-of-view": "^6.0.0",
    "pump": "^3.0.0",
    "puppeteer": "^5.2.1",
    "resolve-from": "^5.0.0",
    "sharp": "^0.25.3",
    "socket.io": "^2.2.0",
    "walk": "^2.3.14",
    "yargs-parser": "^13.1.1"
  },
  "engines": {
    "node": ">=10"
  } 

Any pointers much appreciated

to reproduce git clone git clone https://github.com/johntom/mongodon

johntom commented 2 years ago

I updated all fastify libraries and its working as designed.