No such file or directory
See original GitHub issueI’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:
- Created 7 years ago
- Reactions:9
- Comments:13 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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});
I ran into the same issue, and could solve it by setting the
layoutDir
andpartialsDir
option as follows: