Skip to content

TypeError: Cannot read property 'views' of undefined #223

@scottlet

Description

@scottlet

I've followed the instructions on the website to implement the example but I'm getting

TypeError: Cannot read property 'views' of undefined
    at Proxy.___express (/Users/scott/Development/Gitlab/Freakcity/fcnode/node_modules/express-hbs/lib/hbs.js:453:36)
    at View.render (/Users/scott/Development/Gitlab/Freakcity/fcnode/node_modules/express/lib/view.js:135:8)
    at tryRender (/Users/scott/Development/Gitlab/Freakcity/fcnode/node_modules/express/lib/application.js:640:10)
    at Function.render (/Users/scott/Development/Gitlab/Freakcity/fcnode/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/Users/scott/Development/Gitlab/Freakcity/fcnode/node_modules/express/lib/response.js:1012:7)
    at render (/Users/scott/Development/Gitlab/Freakcity/fcnode/app/routes/home.js:41:9)
    at home (/Users/scott/Development/Gitlab/Freakcity/fcnode/app/routes/home.js:126:9)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

It's like there's a missing options object or something in the code. Do you have any idea where I'm going wrong?

const viewsDir = join(__dirname, 'views');
const layoutsDir = join(viewsDir, 'layouts');

const app = express();

const i18n = new I18n({
    defaultLocale: 'en',
    cookie: 'lang',
    directory: join(__dirname, 'i18n'),
    objectNotation: true
});

app.use(i18n.init);

const hbsEngine = hbs.express4({
    defaultLayout: join(layoutsDir, 'default.hbs'),
    layoutsDir,
    partialsDir: join(viewsDir, 'partials'),
    i18n
});

console.log(hbsEngine);

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

app.set('view engine', '.hbs');
app.set('views', viewsDir);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions