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.

No such file or directory

See original GitHub issue

I’m running into the same issue and it involves the differences in operating systems. This is because the application works as intended on windows, but fails on linux with Error: ENOENT: no such file or directory, open '/views/layouts/main.handlebars'

Here is my file structure.

|-- index.js
|-- package.json
|-- public
|   |-- css
|   |   `-- global.css
|   |-- img
|   `-- js
|       `-- main.js
`-- views
    |-- 404.handlebars
    |-- index.handlebars
    |-- layouts
    |   `-- main.handlebars
    `-- partials
        |-- footer.handlebars
        |-- nav.handlebars
        `-- title.handlebars

and here is part of the index.js file

app.set('views', path.join(__dirname, './views'));
app.engine('handlebars', expressHandlebars({
    defaultLayout: 'main'
}));
app.set('view engine', 'handlebars');

While I was making this issue, I ran into another error Error: Failed to lookup view "index" in views directory "/views" Which contains no reference back to express-handlebars but only mentions express in the stack.

I’m assuming this is just a simple mistake on my part but it might be worth documenting for people like me who don’t quite understand the subtle differences between linux and windows.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:9
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

96reactions
erickhoracommented, Jun 24, 2019

For anyone out there who doesn’t have an layouts or layout folder and is having the same issue. Try this in the rendering of the page: res.render('index', {layout: false});

29reactions
ndeufemiacommented, May 17, 2017

I ran into the same issue, and could solve it by setting the layoutDir and partialsDir option as follows:

app.engine('.hbs', exphbs({
    extname: '.hbs',
    defaultLayout: 'main',
    partialsDir: path.join(__dirname, 'views/partials'),
    layoutsDir: path.join(__dirname, 'views/layouts')
  }));
app.set('view engine', '.hbs');
app.set('views',path.join(__dirname,'views'))
Read more comments on GitHub >

github_iconTop Results From Across the Web

"No such file or directory" but it exists - Stack Overflow
I got this error “No such file or directory” but it exists because my file was created in Windows and I tried to...
Read more >
FileNotFoundError: [Errno 2] No such file or directory
The Python "FileNotFoundError: [Errno 2] No such file or directory" occurs when we try to open a file that doesn't exist in the...
Read more >
Python FileNotFoundError: [Errno 2] No such file or directory ...
The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that...
Read more >
How to Solve No Such File or Directory Error in Python
To solve no such file or directory error in Python, ensure that the file exists in your provided path. To check all the...
Read more >
“.h: No such file or directory" - 2 Easy fixes to Arduino error
The easiest way is to go to Sketch > Include Library > Manage Libraries. The Arduino IDE will open up a dialogue box...
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