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.

Multiple view directories.

See original GitHub issue

Since version 2.0.0 you can no longer use multiple view directories:

With the following code:

server.set('view engine', '.hbs');
server.set('views', [
  dirPath1,
  dirPath2,
  dirPath3
]);

I get: TypeError: Arguments to path.resolve must be strings

This was ok in version 1.1.0, and it appears as though this should be supported when looking at the Express documentation (http://expressjs.com/api.html).

From option views:

A directory or an array of directories for the application’s views. If an array, the views are looked up in the order they occur in the array.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

2reactions
soyainecommented, Sep 4, 2017

When I try to set two folders in the app.set('views', ['views1', 'views2']), I get the error:

TypeError: Path must be a string. Received [ 'views1', 'views1' ]
    at assertPath (path.js:7:11)
    at Object.relative (path.js:1226:5)

But it works well either by app.set('views', 'views1') or app.set('views', 'views2').

After read this issue, I’m puzzled whether have I understand it. But it seems still a lot people suffer from this such as this issue.

I’m trying to find a solution, but it doesn’t look well.

0reactions
morgannewmancommented, May 14, 2019

Not a great long-term solution, but if all your handlebars views are in a single folder, here’s a temporary solution.

const hbsViews = path.join(__dirname, '/views'); // path to your handlebars views
const hbsEngine = exphbs({
  layoutsDir: path.join(__dirname, '/views/layouts'),
  defaultLayout: 'main',
  extname: '.hbs',
});
app.engine(
  '.hbs',
  function(filePath, options, callback) {
    options.settings.views = hbsViews;
    hbsEngine(filePath, options, callback);
  }
);

This works because it fixes this line, which breaks when you set views to be an array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

multiple views directories for one expressjs app
I have defined by views folder structure to be \views\{model}\{operations} . For example: \views\products\add.ejs . When I reference the view in ...
Read more >
Combined view of multiple directories in Linux
Samba is configured to share all three disk (3 separate shares). Disks contain folders an each of them has folderA and folderB containing...
Read more >
Multiple views directories with express-hbs - derp turkey
This article talks about how you can put views in multiple locations and still use Express 4's default view rendering pipeline.
Read more >
Search multiple directories and output file names
This will list all the content of the 7 directory if they are in the same location. Share.
Read more >
Managing Multiple Directories
See centralized user management. Overview. Here is a summary of how the directory order affects the processing: The order of the directories is ......
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