Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
scottlet opened this issue Mar 11, 2021 · 0 comments
Open

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

scottlet opened this issue Mar 11, 2021 · 0 comments

Comments

@scottlet
Copy link

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant