{"id":20488,"library":"rails-erb-loader","title":"rails-erb-loader","description":"Webpack loader that compiles Embedded Ruby (.erb) template files in Ruby/Rails projects by running them through the Erbubis, Erubi, or ERB gem via a Ruby runner (default: bin/rails runner). Version 5.5.2 supports webpack 2–3 via peer dependency and requires Node >= 0.10.0. Configuration options include dependenciesRoot, engine selection, timeout, and environment variables. Dependencies can be declared via magic comments to enable webpack's watch mode. Suitable for mixed JS/Ruby asset pipelines, notably in Rails apps using Webpacker.","status":"active","version":"5.5.2","language":"javascript","source_language":"en","source_url":"https://github.com/usabilityhub/rails-erb-loader","tags":["javascript","erb","loader","webpack","ruby","rails"],"install":[{"cmd":"npm install rails-erb-loader","lang":"bash","label":"npm"},{"cmd":"yarn add rails-erb-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add rails-erb-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - loader is designed to work with webpack module bundler","package":"webpack","optional":false}],"imports":[{"note":"Loader is used in webpack config, not imported as a JavaScript module. It is a CommonJS loader package.","wrong":"import railsErbLoader from 'rails-erb-loader'","symbol":"default (loader)","correct":"module.exports = { module: { rules: [ { test: /\\.erb$/, enforce: 'pre', loader: 'rails-erb-loader' } ] } }"},{"note":"Webpack resolves loaders from node_modules automatically. Use string, not require.resolve.","wrong":"loader: require.resolve('rails-erb-loader')","symbol":"rails-erb-loader (as string)","correct":"loader: 'rails-erb-loader'"},{"note":"Options are plain object on the rule's use entry, not imported. Engine option string, not boolean.","wrong":"options: {erubis: true}","symbol":"options","correct":"const erbLoaderOptions = { runner: './bin/rails runner', dependenciesRoot: 'app', engine: 'erb' }"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nmodule.exports = {\n  entry: './src/index.js',\n  output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' },\n  module: {\n    rules: [{\n      test: /\\.erb$/,\n      enforce: 'pre',\n      loader: 'rails-erb-loader',\n      options: {\n        runner: './bin/rails runner',\n        dependenciesRoot: 'app',\n        engine: 'erb'\n      }\n    }]\n  }\n};","lang":"javascript","description":"Configure webpack to preprocess .erb files using rails-erb-loader with custom runner and engine options."},"warnings":[{"fix":"Use an alternative loader (e.g., erb-loader) or stick to webpack 2/3.","message":"webpack 4+ not supported; requires webpack 2 or 3. This loader may not work with modern webpack versions.","severity":"breaking","affected_versions":">=5.5.2"},{"fix":"Explicitly set dependenciesRoot to the correct path relative to webpack's working directory.","message":"The 'dependenciesRoot' option defaults to 'app' which assumes Rails conventions; may not work in non-standard layouts.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"For non-Rails projects, set 'runner' option to 'ruby' and 'engine' to 'erb' in loader options.","message":"Ruby runner must be installed and configured; default './bin/rails runner' requires a Rails app. Without Rails, set runner to 'ruby'.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Set 'timeoutMs' to a reasonable value (e.g., 10000) to prevent hanging builds.","message":"Timeout of 0 (default) means no timeout; a hanging Ruby process can block build indefinitely.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Use correct comment format: /* rails-erb-loader-dependencies path/to/file */","message":"Dependency comments must start with 'rails-erb-loader-dependencies' or 'rails-erb-loader-dependency' exactly; misspelling will not work.","severity":"gotcha","affected_versions":">=5.0.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 rails-erb-loader --save-dev","cause":"Loader not installed as a devDependency.","error":"ERROR in ./app/assets/javascripts/application.js.erb\nModule build failed: Error: Cannot find module 'rails-erb-loader'"},{"fix":"Set runner option to correct path relative to webpack's working directory, or generate binstubs: bundle exec rails app:update:bin","cause":"Runner path incorrect or missing binstub.","error":"ERROR in ./app/assets/javascripts/application.js.erb\nModule build failed: Error: Command failed: ./bin/rails runner ...\n/bin/sh: ./bin/rails: No such file or directory"},{"fix":"Ensure rule has test: /\\.erb$/ and enforce: 'pre' in webpack config.","cause":"Loader is not applied because test regex doesn't match, or enforce: 'pre' is missing.","error":"Child compilation failed:\nModule parse failed: ... Unexpected token (1:0)\nYou may need an appropriate loader to handle this file type."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}