How to Resolve Error: Cannot find module 'ejs' ?
Last Updated :
28 Apr, 2025
EJS (Embedded JavaScript) is the templating engine for JS that simplifies the task of generation of HTML markup with embedded JS code. It allows you to embed dynamic content and logic directly within the HTML templates, which makes it easier to generate dynamic web pages in Node.js Apps. While working with this engine, developers usually face the Cannot find module 'ejs' error. In this article, we will learn how to fix or resolve this error.
What is the "Cannot find module 'ejs'" Error?
The Cannot find module 'ejs' error occurs when the Node.js application cannot locate the required ejs module in the application. Some possibilities and occurrence scenarios encounter this error while trying to use ejs module. This error suggests that this module is not installed or it may be named differently. It is important to verify the correct installation of the required module and also ensure that the module's name matches correctly.
Error Sample:

Why does "Cannot find module 'ejs'" occur?
Below, are the reasons for "Cannot find module 'ejs'" occurring:
- Module Not Installed
- Incorrect Module Name
Reason 1: Module Not Installed
In this scenario, Node.js script uses the 'ejs' module to read an EJS template from 'index.ejs', compiles it, replaces a variable with the value 'World', generates HTML, and writes it to 'output.html'. But, as the module is not installed, it will give the Error as "Cannot find module 'ejs'". Without installing the module, we cannot use ejs.
JavaScript
const ejs = require('ejs');
const fs = require('fs');
const template = fs.readFileSync('index.ejs', 'utf-8');
const compiledTemplate = ejs.compile(template);
const data = { name: 'World' };
const renderedHTML = compiledTemplate(data);
fs.writeFileSync('output.html', renderedHTML);
console.log('HTML file generated successfully!');
Output:
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module 'ejs'
Reason 2: Incorrect Module Name
Another reason for the error mighr be a typing mistake or incorrect naming when trying to import the ejs module. Node.js is case-sensitive, so ensure that the module name is spelled correctly.
JavaScript
const ejs = require('EJS'); // Incorrect
Output:
node:internal/modules/cjs/loader:998
throw err;
^
Error: Cannot find module 'EJS'
Below are the solutions for "Cannot find module 'ejs'" Error:
Approach 1: Install ejs Module
We can resolve this error by installing the ejs module externally using npm package manager. Execute the below command in the terminal to install the module.
Command:
npm install ejs
Once we execute the command, it will take a couple of minutes to completely install the package according to the internet speed.

Once the installation is completed, try to import the package and verify whether the error is resolved or not. We can also check by verifying the version of ejs using below command.
npm show ejs version

Approach 2: Correct the Spelling Mistake
Sometimes, the error occurs due to the spelling mistake while importing the module. So, we can correct the spelling mistake while importing this module.
const ejs = require('ejs'); // Correct
By following these approaches the will definitely be resolved.
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read