Express res.render fails: no default engine was specified and no extension was provided
Error: No default engine was specified and no extension was provided.Short answer
Express builds the template file name from the view name plus the view engine setting. If the name has no extension and view engine is not set, it throws this error. Set app.set('view engine', 'ejs') before the routes, spell the key with a space, or write the extension in the render call.
Fix it fast
1Find out which cause you have
Search the app for the view engine setting and for every res.render call. You need a setting, or an extension in the name.
grep -rn "view engine\|view-engine\|res.render\|app.engine" --include=*.js . --exclude-dir=node_modules2Match what you see, then jump to its fix
- 1
res.render('index') with no extension and no app.set('view engine', ...) anywhereview engine was never setFix - 2
A view engine line exists, but uses view-engine, viewengine or view_engineThe setting key is spelled wrongFix - 3
You render a file such as index.html, whose extension is not the name of a template engine packageThe extension has no matching engine module (html files)Fix
- 1
What does the error look like?
Error: No default engine was specified and no extension was provided.at new View (node_modules/express/lib/view.js)
Cause 1 of 3
view engine was never set
1Check
The Express docs say the view engine setting is the default engine extension to use when omitted, and that its default is undefined. In the Express source, a view name with no extension plus no default engine throws this exact error.
grep -rn "set('view engine'" --include=*.js . --exclude-dir=node_modules2Fix
Install the engine and set it on the app that calls res.render.
npm install ejs
// app.js
app.set('view engine', 'ejs');
app.set('views', './views');3Verify
Restart and open the route; views/index.ejs renders.
curl -i http://localhost:3000/Confirmed by expressjs.com
Cause 2 of 3
The setting key is spelled wrong
1Check
The documented setting name is 'view engine' with a space. Express reads that exact key, so a near-miss key is stored but never used.
grep -rnE "app\.set\(['\"]view[-_]?engine" --include=*.js . --exclude-dir=node_modules2Fix
Rename the key to the documented one.
// wrong
app.set('view-engine', 'ejs');
// right
app.set('view engine', 'ejs');3Verify
Request the page again.
curl -i http://localhost:3000/Confirmed by expressjs.com
Cause 3 of 3
The extension has no matching engine module (html files)
1Check
By default Express calls require() with the file extension as the module name, and that module must export __express. There is no engine called html, so .html views need an explicit registration.
ls views && grep -rn "app.engine" --include=*.js . --exclude-dir=node_modules2Fix
Register an engine for the extension with app.engine, or rename the views to the engine's own extension.
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');3Verify
Render a view that has a variable and check it is filled in.
curl -s http://localhost:3000/ | headConfirmed by expressjs.com
How do I stop it coming back?
- Put app.set('view engine', ...) and app.set('views', ...) in one place, above the routes.
- Keep one engine and one extension per project, so a view name never needs the extension.
- Add a smoke test that requests a page that renders a view.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Express answers Cannot GET for a page that should exist
Cannot GET /api/users
Cannot GET is Express's default reply when no route or static file matches the request.
4 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fix