How to fix Error: View engine 'pug' not found (view engine not installed) in Node.js

Node.jsBEGINNERHIGHUpdated Dec 9, 2025ยท 111 views

This error occurs when Express cannot locate the view engine you specified in your application. It typically happens when the view engine package is not installed, the engine name is misspelled, or the engine is not properly registered.

Quick fix

Fixes ERR_VIEW_ENGINE_NOT_FOUND

npm install pug
  1. Install the required view engine package
  2. Verify the view engine name matches the package
  3. Check package.json and node_modules
  4. Verify views directory path
node.js โ€” error
npm install pug
Error: View engine 'pug' not found (view engine not installed)
shell
npm install pug

What this error means

The "View engine not found" error means Express tried to render a view using a template engine (like Pug, EJS, Handlebars, etc.) but couldn't find that engine installed in your project. Express relies on view engines to transform template files into HTML that gets sent to the browser. When you set a view engine with `app.set('view engine', 'pug')` and then render a view with `res.render('myTemplate')`, Express looks for an installed npm package that provides that engine. If the package isn't installed or isn't registered correctly, you get this error. The error message includes the name of the missing engine, making it easy to identify which package you need to install.

Typical symptoms

  • Application crashes with 'view engine not found' when attempting to render a page
  • Error appears in server logs after calling res.render()
  • Static pages work fine, but dynamic template rendering fails
  • Pages work locally but fail after deployment
  • Error specifies the exact engine name (e.g., 'pug', 'ejs', 'handlebars')

Common causes

  1. The view engine package was never installed with npm
  2. The view engine is listed only in devDependencies (not available in production)
  3. The node_modules directory is missing or incomplete
  4. Typo in the view engine name (e.g., 'pag' instead of 'pug')
  5. Outdated Express or view engine version with compatibility issues
  6. View engine package was installed globally instead of locally
  7. Node.js version doesn't support the specified view engine version

How to fix "Error: View engine 'pug' not found (view engine not installed)"

1Install the required view engine package

Install the missing view engine package locally in your project. For Pug:

bash
npm install pug

For other popular engines:

bash
npm install ejs
npm install hbs
npm install handlebars
npm install nunjucks
npm install mustache

Always use npm install (not -g global flag) to install packages that your application code depends on.

2Verify the view engine name matches the package

Ensure the engine name in your Express code exactly matches the installed package. For example:

javascript
const express = require('express');
const app = express();

// Set the view engine to pug
app.set('view engine', 'pug');

// Set the views directory (where template files are stored)
app.set('views', './views');

app.get('/', (req, res) => {
  // This will look for ./views/index.pug
  res.render('index', { title: 'Home' });
});

Common engine names:
- pug - for the pug package
- ejs - for the ejs package
- hbs - for the hbs (Handlebars) package
- nunjucks - for the nunjucks package

Avoid typos and use lowercase (engine names are case-sensitive).

3Check package.json and node_modules

Open your package.json and verify the view engine is listed in dependencies (not devDependencies):

json
{
  "dependencies": {
    "express": "^4.18.2",
    "pug": "^3.0.2"
  }
}

If the package is only in devDependencies, move it to dependencies. Then check that node_modules exists and contains the package:

bash
ls node_modules/pug

If node_modules is missing or incomplete, run a clean reinstall:

bash
rm -rf node_modules package-lock.json
npm install
4Verify views directory path

Ensure the directory specified with app.set('views', path) exists and contains your template files:

javascript
const path = require('path');
const express = require('express');
const app = express();

// Correct: Use path.join for cross-platform compatibility
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.get('/', (req, res) => {
  // Express will look for ./views/index.pug
  res.render('index');
});

Create the views directory if it doesn't exist:

bash
mkdir -p views

Place your template files in this directory with the appropriate extension (e.g., index.pug, profile.pug).

5Register custom view engines if needed

If you're using a less common view engine or a custom implementation, you may need to explicitly register it with Express:

javascript
const express = require('express');
const nunjucks = require('nunjucks');
const app = express();

// Register nunjucks as the view engine
nunjucks.configure('views', { autoescape: true });
app.engine('html', nunjucks.render);
app.set('view engine', 'html');

app.get('/', (req, res) => {
  res.render('index');
});

Check the documentation of your specific view engine for registration instructions, especially for less common engines or custom solutions.

Advanced notes

Production deployments: View engines must be in dependencies, not devDependencies. When deploying to platforms like Heroku, Railway, or Vercel, npm install --production skips devDependencies, causing this error if your engine is misplaced.

Multiple view engines: You can register multiple view engines in the same Express app:

javascript
app.engine('pug', require('pug').__express);
app.engine('html', require('nunjucks').render);

Docker/containerization: When using Docker, ensure your view engine is installed during the build phase. Your Dockerfile should copy package.json and run npm install before copying your application code.

TypeScript with Express: When using TypeScript with Express, ensure @types/express is installed and the view engine's types are available (some engines include TypeScript definitions, others require separate @types packages).

Custom view engines: If you're building a custom view engine, ensure it's properly exported and accessible. Custom engines should follow Express conventions for engine functions.

Frequently asked questions

What does "ERR_VIEW_ENGINE_NOT_FOUND" mean?
) but couldn't find that engine installed in your project. Express relies on view engines to transform template files into HTML that gets sent to the browser. render('myTemplate'), Express looks for an installed npm package that provides that engine.
How do I fix "ERR_VIEW_ENGINE_NOT_FOUND"?
This error occurs when Express cannot locate the view engine you specified in your application. It typically happens when the view engine package is not installed, the engine name is misspelled, or the engine is not properly registered.
What causes "ERR_VIEW_ENGINE_NOT_FOUND"?
The view engine package was never installed with npm The view engine is listed only in devDependencies (not available in production) The node_modules directory is missing or incomplete
Is the "ERR_VIEW_ENGINE_NOT_FOUND" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading