ejs-lint

raw JSON →
2.0.1 verified Fri May 01 auth: no javascript

Linter and syntax checker for EJS templates. Version 2.0.1 released September 2022. ESM-only since v2, requires Node 14+. Parses scriptlet and expression tags, replacing template output with whitespace to retain line/column numbers, then validates resulting JavaScript with acorn via node-syntax-error. Distinguishes itself from EJS core by providing meaningful syntax error messages with line context, supporting custom delimiters, CLI and API usage. Does not check for unclosed EJS tags but helps detect malformed scriptlets. Alternatives exist (e.g., eslint-plugin-ejs) but ejs-lint is the standalone, lightweight option.

error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
cause Using CommonJS require() on EJS-Lint v2+
fix
Switch to import or use dynamic import: const ejsLint = (await import('ejs-lint')).default;
error SyntaxError: Unexpected token (1:5) - line doesn't contain any scriptlets
cause Forgot to close an EJS tag earlier in the template
fix
Double-check all <% and %> tags are properly closed.
breaking v2.0.0 switched to ESM-only; CommonJS require() will fail
fix Update code to use import statements or use dynamic import().
breaking v2.0.0 dropped Node 12 support; requires Node 14+
fix Upgrade Node.js to version 14 or higher.
breaking v1.0.0 removed deprecated .lint() alias; use ejsLint() instead
fix Replace .lint(text, options) with ejsLint(text, options).
breaking v0.3.0 removed parse() method and --parse CLI option
fix Use ejsLint() API or ejslint CLI only.
gotcha Does not detect unclosed EJS tags; will show confusing errors on lines without scriptlets
fix Manually check for unclosed <% or %> before blaming the linter.
npm install ejs-lint
yarn add ejs-lint
pnpm add ejs-lint

Shows how to use the ejsLint API to check an EJS template for syntax errors.

import ejsLint from 'ejs-lint';

const template = `<% if (user) { %>
  <h1><%= user.name %></h1>
<% } else { %>
  <h1>No user</h1>
<% } %>`;

const err = ejsLint(template, { delimiter: '%' });
if (err) {
  console.error(`Syntax error at line ${err.line}, column ${err.column}: ${err.message}`);
} else {
  console.log('Template is valid');
}