Express tries to load a module called html and cannot find it
Error: 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.
Fix it fast
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 .2Match what you see, then jump to its fix
- 1
app.set('view engine', 'html') and no app.engine('html', ...) anywhereThe html extension has no engine registeredFix - 2
The 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
Cannot find module 'pug' (or the engine you chose) instead of htmlThe chosen engine package is not installed or does not follow the Express conventionFix
- 1
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 hbs2Fix
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
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/aboutConfirmed by expressjs.com
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 hbs2Fix
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 hbs3Verify
Restart the app and render one view.
node server.jsConfirmed by expressjs.com
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
Back end
res.render fails because Express cannot find the template file
Failed to lookup view "home" in views directory
Express builds a file path from the views setting, the view name and the view engine extension, then looks for that file.
2 causes, each with a fixBack end
Express res.render fails: no default engine was specified and no extension was provided
at new View (node_modules/express/lib/view.js)
Express builds the template file name from the view name plus the view engine setting.
3 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 fix