teamwethrift / simple-express-handlebars-boilerplate

A minimal ExpressJS server boilerplate using Handlebars view engine.
4 stars 5 forks source link

Missing layouts folder and its files #1

Open wicaksana94 opened 4 years ago

wicaksana94 commented 4 years ago

Error: ENOENT: no such file or directory, open 'simple-express-handlebars-boilerplate\views\layouts\main.handlebars'

How I got this error :

  1. I clone the repo
  2. Run npm install
  3. Run npm start
ivandi1980 commented 3 years ago

@wicaksana94 you have to create folder layouts inside views and create file main.handlebars inside layout


views\layouts\main.handlebars

why? because if you search on node_modules/express-handlebars/express-handlebars.js you can find these code :

var view; var viewsPath = options.settings && options.settings.views; 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/'); }

and this code :

function ExpressHandlebars(config) { // Config properties with defaults. utils.assign(this, { handlebars: Handlebars, extname: '.handlebars', layoutsDir: undefined, // Default layouts directory is relative toexpress settings.view+layouts/ partialsDir: undefined, // Default partials directory is relative toexpress settings.view+partials/ defaultLayout: 'main', helpers: undefined, compilerOptions: undefined, }, config);

first, when i cloned this repo, i was faced the problems like you did, but you can use my way to solve it...

wicaksana94 commented 3 years ago

@wicaksana94 you have to create folder layouts inside views and create file main.handlebars inside layout

views\layouts\main.handlebars

why? because if you search on node_modules/express-handlebars/express-handlebars.js you can find these code :

var view; var viewsPath = options.settings && options.settings.views; 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/'); }

and this code :

function ExpressHandlebars(config) { // Config properties with defaults. utils.assign(this, { handlebars: Handlebars, extname: '.handlebars', layoutsDir: undefined, // Default layouts directory is relative toexpress settings.view+layouts/partialsDir: undefined, // Default partials directory is relative toexpress settings.view+partials/defaultLayout: 'main', helpers: undefined, compilerOptions: undefined, }, config);

first, when i cloned this repo, i was faced the problems like you did, but you can use my way to solve it...

Okay @ivandi1980 , I'll do PR