Home > other >  Issue with express-handlebars new version(6.0.1)
Issue with express-handlebars new version(6.0.1)

Time:11-21

var express = require('express');
var hbs= require('express-handlebars')
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.engine('hbs', hbs({
    layoutsDir: `${__dirname}/views/layouts`,
    extname: `hbs`,
    defaultLayout: 'layout',
    partialsDir: `${__dirname}/views/partials`
}))

no problem while using version(5.3.4) of express-handlebars but it's not working with the new version(6.0.1) it is showing hbs is not a functionTypeError: hbs is not a function

CodePudding user response:

According to the documentation there is a new create function where you pass your JSON config then define the hbs.engine with the app.engine function.

Example:

const express = require("express");
const { create } = require("express-handlebars");
const app = express();

const hbs = create({
    layoutsDir: `${__dirname}/views/layouts`,
    extname: `hbs`,
    defaultLayout: 'layout',
    partialsDir: `${__dirname}/views/partials`
});

app.engine('hbs', hbs.engine);

// Continue code
  • Related