Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default (loader)
✓ const template = require('ejs-loader!./file.ejs');
✗ import template from 'ejs-loader!./file.ejs';
Webpack loaders are not ESM-compatible in import statements; use require() for loader-returned modules.
default (template function)
✓ const compiled = require('ejs!./file.ejs'); const html = compiled({ name: 'John' });
✗ const html = require('ejs!./file.ejs')({ name: 'John' });
The returned module is a function that you call with data; it is not the rendered HTML.
webpack config (module.rules)
✓ module.exports = { module: { rules: [ { test: /\.ejs$/, use: ['ejs-loader'] } ] } };
✗ module.exports = { module: { loaders: [ { test: /\.ejs$/, loader: 'ejs-loader' } ] } };
Webpack 4+ uses 'module.rules' and 'use' array; the old 'module.loaders' with 'loader' string is deprecated.
Shows a minimal webpack 4+ config with ejs-loader, ProvidePlugin for lodash, and usage of the compiled template function.
// webpack.config.js
const webpack = require('webpack');
module.exports = {
entry: './src/index.js',
module: {
rules: [
{
test: /\.ejs$/,
use: [
{
loader: 'ejs-loader',
options: { variable: 'data' }
}
]
}
]
},
plugins: [
new webpack.ProvidePlugin({ _: 'lodash' })
]
};
// src/index.js
const template = require('./template.ejs');
const html = template({ name: 'World' });
document.body.innerHTML = html;
// src/template.ejs
<h1>Hello <%= data.name %>!</h1>
Errors
Common errors & fixes
Module not found: Error: Cannot resolve module 'ejs-loader'
ejs-loader is not installed.
fixRun 'npm install ejs-loader --save-dev'.
Error: ejs-loader: You must provide a 'variable' option when using ES modules.
Missing 'variable' option in loader configuration with esModule: true (default).
fixAdd options: { variable: 'data' } to the loader rule. Uncaught ReferenceError: _ is not defined
Lodash/underscore is not provided globally at runtime.
fixAdd new webpack.ProvidePlugin({ _: 'lodash' }) to webpack plugins. Uncaught TypeError: template is not a function
The required module is not being used as a function; it's the compiled template function.
fixCall the required module: const html = require('./template.ejs')({ data }); Audit
Dependencies
lodashrequiredRuntime dependency for template compilation