Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Express res.render fails: no default engine was specified and no extension was provided

ErrorError: 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.

  • Applies to Express 4, EJS 3, Node.js 22 and 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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_modules
  2. 2Match what you see, then jump to its fix

    1. 1res.render('index') with no extension and no app.set('view engine', ...) anywhereview engine was never setFix
    2. 2A view engine line exists, but uses view-engine, viewengine or view_engineThe setting key is spelled wrongFix
    3. 3You 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

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_modules

2Fix

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

Did this fix it?

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_modules

2Fix

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

Did this fix it?

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_modules

2Fix

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/ | head

Confirmed by expressjs.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.