question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

configuration `layoutsDir` & `partialsDir` is invalid

See original GitHub issue

After 3.0.1 was released, the configuration options layoutsDir and partialsDir became invalid.

utils.assign(this, {
        handlebars     : Handlebars,
        extname        : '.handlebars',
        layoutsDir     : 'views/layouts/',
        partialsDir    : 'views/partials/',
        defaultLayout  : undefined,
        helpers        : undefined,
        compilerOptions: undefined,
}, config);

Because after Fixes #147, the custom configuration options layoutsDir and partialsDir will be overridden.

    var viewsPath = options.settings && options.settings.views;
    if (viewsPath) {
        view = this._getTemplateName(path.relative(viewsPath, viewPath));
        this.partialsDir = path.join(viewsPath, 'partials/');
        this.layoutsDir = path.join(viewsPath, 'layouts/');
    }

I hope it can be repaired as soon as possible.Thank you.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:6

github_iconTop GitHub Comments

3reactions
dogbutcatcommented, Feb 21, 2019

Yeah, I also found it. It is needed when developer not defined the layoutsDir and partialsDir as given default config path here is relative https://github.com/ericf/express-handlebars/blob/5d27bb50ba299d7ba185dfc5b9f8057bf7129256/lib/express-handlebars.js#L24-L32

so I think maybe change like this is fine for global custom one or default one

    utils.assign(this, {
        handlebars     : Handlebars,
        extname        : '.handlebars',
       // layoutsDir     : 'views/layouts/',
       // partialsDir    : 'views/partials/',
        defaultLayout  : undefined,
        helpers        : undefined,
        compilerOptions: undefined,
    }, config);

and

    if (viewsPath) {
        view = this._getTemplateName(path.relative(viewsPath, viewPath));
        this.partialsDir =  this.partialsDir || path.join(viewsPath, 'partials/');
        this.layoutsDir = this.layoutsDir || path.join(viewsPath, 'layouts/');
    }

I changed on my local like this and it work fine with my old settings

2reactions
sahatcommented, Feb 24, 2019

Thank you for reporting the issue. The bug has been fixed and the new version v3.0.2 is now published on npm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A partials dir must be a string or config object in handlebars ...
I had to add the partialsDir to my handlebarOptions where I didn't have the field before: const handlebarOptions = { viewEngine: { extName: ......
Read more >
express-handlebars - npm
layoutsDir. Default layouts directory is relative to express settings.view + layouts/ The string path to the directory where the layout ...
Read more >
A partials dir must be a string or config object in handlebars ...
Coding example for the question Error: A partials dir must be a string or config object in handlebars-node.js.
Read more >
A Step By Step Guide To Using Handlebars With Your Node js ...
Setting Up A Basic Express Server. Let's start by creating a folder which will contain our app and within it type the following...
Read more >
WEB322 Week 6 Notes
sendFile(path.join(__dirname, "/week2-assets/about.html")); }); // setup ... of Express Handlebars require the layout to be explicitly set to “false” if not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found