Partials not found
See original GitHub issueNo matter what I do to include partials, I always receive the following error “Error: ENOENT: no such file or directory”. The EJS include does not resolve the partial, even if I move the partials to the same level as the ‘entry’ ejs file. I’m running with webpack-dev-server.
What I’m trying to do:
I have existing EJS files, I want to compile them (and their partials), then have the project accessible from dist/index.html (using html-webpack-plugin, see below). Previously this was a gulp task.
Project structure: app/
- layouts/default.ejs
- main.ejs
- webpack.config.js
scripts/
- main.js
assets/ dist/
In main.ejs, I have:
<%- include layouts/default -%>
Relevant parts of webpack.config looks like:
const appDir = path.resolve(__dirname, 'app'),
distDir = path.resolve(__dirname, 'dist')
---
output: {
devtoolLineToLine : true,
sourceMapFilename : 'main.js.map',
pathinfo : true,
path : distDir,
filename : 'main.js'
},
module : {
loaders: [
{
test: /.ejs$/,
loader: 'ejs-compiled'
},
//Run JS through babel-loader
{
test : /.js$/,
loader : 'babel-loader',
include: appDir,
exclude: /node_modules/,
query : {
plugins: ['lodash'],
presets: ['es2015'],
}
},
..
}
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js'),
new HtmlWebpackPlugin({
title : 'Puzzle Slider Proto',
template : '!!ejs-compiled-loader!' + appDir + '/main.ejs'
})
]
I’m using ES6 with: “ejs-compiled-loader”: “^1.1.0”, “babel-loader”: “^6.2.5”, “html-webpack-plugin”: “^2.24.1”,
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:9
Top Results From Across the Web
How to Solve The partial head could not be found Handlebars
I run ExpressJS and installed Handlebars as a template engine. I'm using AdminLTE and split it up to 6 hbs files in /views/layouts...
Read more >Partials not found · Issue #151 · pillarjs/hbs - GitHub
Hi. Im trying to include hbs partials on my main.hbs but im getting an error that partials could not be found.
Read more >How to fix Hugo's 'partial not found' error message? - Kodify.net
The 'partial not found' error message happens when Hugo cannot find a partial that we reference in a theme template file (GitHub, 2017)....
Read more >New partials not working in handlebars example - Glitch Support
Hi, I am trying to use a remix of the handlebars template example which works fine until I create new partials and include...
Read more >Partials | Handlebars
The normal behavior when attempting to render a partial that is not found is for the implementation to throw an error. If failover...
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 Free
Top 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
I found the solution, while the ejs official doc says that the syntax for import is
<%- include('user/show'); %>
it is actually<%- include user/show %>
, I found it here.I replace my includes with this new simpler syntax and webpack now compiles fine.
Do not forget to include with the path relative to your webpack config file.
Also, if you want to compile your file with CLI (not in runtime), like I do with gulp and gulp-ejs plugin; you must prefix your includes with
/
(like root path) (ex:<%- include /project_root/some_dir/user/show %>
) and then set in ejs option{"root": __dirname}
in your gulp file where__dirname
is the absolute path of yourproject_root
.Right after posting this… tried it without any pathing on the templates, and with version 2.0.0 it works.
Using this works:
I think the confusion about NPM serving version 1 needs to be cleared up. From then on its just a matter of configuring it how EJS recommends: https://github.com/tj/ejs#includes