ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

TypeError: exphbs is not a function #295

Closed moshema10 closed 3 years ago

moshema10 commented 3 years ago

I am using handlebars for the first time in my project. I am facing this type error. Can anyone help me fix this?

CODE:

const express = require('express'); const app = express(); const bodyParser = require('body-parser'); const exphbs = require('express-handlebars');

app.use(express.static(__dirname + "/public")); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true}));

app.set("view engine","hbs"); app.engine('hbs',exphbs({ extname: 'hbs', defaultLayout: 'index' }));

ERROR:

app.engine('hbs',exphbs({ ^

TypeError: exphbs is not a function

UziTech commented 3 years ago

The latest version removed the default export.

const { engine } = require('express-handlebars');
...
app.engine('hbs',engine({...
moshema10 commented 3 years ago

Thanks @UziTech It worked!!!