Skip to content

Array for views gives "TypeError: Arguments to path.resolve must be strings" #124

@sundarj

Description

@sundarj

Hi, I have express-handlebars 2.0.0 on express 4.12.3, and I think I've discovered a bug.

The aforementioned TypeError gets raised when I try and render a view. The line that seems to be causing it is line 193 of express-handlebars.js: view = this._getTemplateName(path.relative(viewsPath, viewPath)). Since I've passed an array to app.set('views'), viewsPath is also an array, and thus raises that error. I'd try and fix it myself, but I don't really know how I'd go about that.

Just in case it helps, here is my index.js (the error occurs when I visit /resonate/bts/editor):

var express = require('express');
var path = require('path');
var fs = require('fs');
var hbs = require('express-handlebars');
var app = express();

app.set('view options', {layout: false});
app.engine('.rsn', hbs({extname: '.rsn'}));
app.set('view engine', '.rsn');
app.set('views', [
  path.join(__dirname, 'resonate/bts',
  path.join(__dirname, 'resonate/template')
]);

app.enable('trust proxy');

...

var files = [];
walk('resonate/template', function(f,s) {
  files.push(f);
});

app.get('/resonate/bts/editor', function(req, res) {
  res.render('editor', {
    files: files
  });
});

app.use(require('compression')());
app.use(express.static(__dirname));
app.listen(8080);

Any ideas would be fantastic, thank you!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions