{"id":19455,"library":"ejs-loader","title":"ejs-loader","description":"Webpack loader that compiles EJS templates using lodash/underscore's _.template function. Current stable version is 0.5.0, with maintenance releases every few years. Key differentiator from ejs-compiled-loader: it uses lodash/underscore template syntax, not the EJS templating engine. Requires ProvidePlugin for global '_'. Supports custom delimiters via options, and ES module export by default with an option to switch to CommonJS. The 'variable' option is required to avoid strict mode errors with ES modules.","status":"active","version":"0.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/difelice/ejs-loader","tags":["javascript","ejs","underscore","lodash","_","webpack","loader","template"],"install":[{"cmd":"npm install ejs-loader","lang":"bash","label":"npm"},{"cmd":"yarn add ejs-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add ejs-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for template compilation","package":"lodash","optional":false}],"imports":[{"note":"Webpack loaders are not ESM-compatible in import statements; use require() for loader-returned modules.","wrong":"import template from 'ejs-loader!./file.ejs';","symbol":"default (loader)","correct":"const template = require('ejs-loader!./file.ejs');"},{"note":"The returned module is a function that you call with data; it is not the rendered HTML.","wrong":"const html = require('ejs!./file.ejs')({ name: 'John' });","symbol":"default (template function)","correct":"const compiled = require('ejs!./file.ejs'); const html = compiled({ name: 'John' });"},{"note":"Webpack 4+ uses 'module.rules' and 'use' array; the old 'module.loaders' with 'loader' string is deprecated.","wrong":"module.exports = { module: { loaders: [ { test: /\\.ejs$/, loader: 'ejs-loader' } ] } };","symbol":"webpack config (module.rules)","correct":"module.exports = { module: { rules: [ { test: /\\.ejs$/, use: ['ejs-loader'] } ] } };"}],"quickstart":{"code":"// webpack.config.js\nconst webpack = require('webpack');\nmodule.exports = {\n  entry: './src/index.js',\n  module: {\n    rules: [\n      {\n        test: /\\.ejs$/,\n        use: [\n          {\n            loader: 'ejs-loader',\n            options: { variable: 'data' }\n          }\n        ]\n      }\n    ]\n  },\n  plugins: [\n    new webpack.ProvidePlugin({ _: 'lodash' })\n  ]\n};\n\n// src/index.js\nconst template = require('./template.ejs');\nconst html = template({ name: 'World' });\ndocument.body.innerHTML = html;\n\n// src/template.ejs\n<h1>Hello <%= data.name %>!</h1>","lang":"javascript","description":"Shows a minimal webpack 4+ config with ejs-loader, ProvidePlugin for lodash, and usage of the compiled template function."},"warnings":[{"fix":"Add 'variable: 'data'' to loader options in webpack config.","message":"The 'variable' option is required for the loader to work with ES module exports; otherwise strict mode errors occur.","severity":"gotcha","affected_versions":">=0.5.0"},{"fix":"Use 'module.rules' array with 'use' array and 'loader' string inside object.","message":"Using 'module.loaders' array and 'loader' string is deprecated in webpack 4+.","severity":"deprecated","affected_versions":">=0.3.1"},{"fix":"Call the required module as a function: const html = template(data);","message":"The loader returns a template function, not the rendered HTML string; you must call it with data.","severity":"gotcha","affected_versions":">=0.3.0"},{"fix":"Add new webpack.ProvidePlugin({ _: 'lodash' }) to plugins in webpack config.","message":"Requires a global '_' variable (lodash/underscore) at runtime; use ProvidePlugin.","severity":"gotcha","affected_versions":">=0.3.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install ejs-loader --save-dev'.","cause":"ejs-loader is not installed.","error":"Module not found: Error: Cannot resolve module 'ejs-loader'"},{"fix":"Add options: { variable: 'data' } to the loader rule.","cause":"Missing 'variable' option in loader configuration with esModule: true (default).","error":"Error: ejs-loader: You must provide a 'variable' option when using ES modules."},{"fix":"Add new webpack.ProvidePlugin({ _: 'lodash' }) to webpack plugins.","cause":"Lodash/underscore is not provided globally at runtime.","error":"Uncaught ReferenceError: _ is not defined"},{"fix":"Call the required module: const html = require('./template.ejs')({ data });","cause":"The required module is not being used as a function; it's the compiled template function.","error":"Uncaught TypeError: template is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}