Maaz Zindani

Loading the index…

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

Express tries to load a module called html and cannot find it

ErrorError: Cannot find module 'html'

Short answer

Express loads a template engine module named after the file extension. When the view engine is set to html, it tries require('html') and no such engine is installed. Either map the html extension to an engine you installed, such as EJS, or serve plain files with express.static or res.sendFile instead.

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

Fix it fast

  1. 1Find out which cause you have

    Look for the line that sets the view engine. If it says html and no app.engine line follows, this page is the right one.

    grep -rn "view engine\|app.engine" --include=*.js .
  2. 2Match what you see, then jump to its fix

    1. 1app.set('view engine', 'html') and no app.engine('html', ...) anywhereThe html extension has no engine registeredFix
    2. 2The files contain no template tags, and res.render was only used to send themThe page is plain static HTML and needs no template engineFix
    3. 3Cannot find module 'pug' (or the engine you chose) instead of htmlThe chosen engine package is not installed or does not follow the Express conventionFix

What does the error look like?

  • Error: Cannot find module 'html'

Cause 1 of 3

The html extension has no engine registered

1Check

By default Express runs require() on a module named like the extension and uses its __express function. There is no engine called html, so the require fails.

npm ls ejs pug hbs

2Fix

Install an engine whose syntax you want inside the file, then map the html extension to it.

npm install ejs

// server.js
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

3Verify

Render a page through res.render and open it.

curl -i http://localhost:3000/

Confirmed by expressjs.com

Did this fix it?

Cause 2 of 3

The page is plain static HTML and needs no template engine

1Check

res.render is for templates that get variables. A finished HTML file is a static asset.

grep -rn "res.render" --include=*.js .

2Fix

Serve the folder with express.static, or send one file with an absolute path or the root option.

const path = require('node:path');
app.use(express.static(path.join(__dirname, 'public')));
app.get('/about', (req, res) => {
  res.sendFile('about.html', { root: path.join(__dirname, 'public') });
});

3Verify

Request the page; the HTML file comes back unchanged.

curl -i http://localhost:3000/about

Confirmed by expressjs.com

Did this fix it?

Cause 3 of 3

The chosen engine package is not installed or does not follow the Express convention

1Check

The engine package must be in node_modules. An engine without an __express function does not work unaided; the docs name consolidate and hbs as ways around that.

npm ls pug ejs hbs

2Fix

Install the package, or switch to an Express-ready one such as hbs instead of the raw handlebars package.

npm install pug
# or, for Handlebars
npm install hbs

3Verify

Restart the app and render one view.

node server.js

Confirmed by expressjs.com

Did this fix it?

How do I stop it coming back?

  • Pick one rule: templates go through res.render, finished HTML goes through express.static.
  • Commit package-lock.json so a fresh install has the same engine.
  • Keep app.engine and app.set('view engine') next to each other in the file.

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.