{"id":21288,"library":"esbuild-rails","title":"esbuild-rails","description":"Esbuild plugin for Rails applications that enables glob imports for Stimulus controllers, ActionCable channels, and other JavaScript files. Current stable version is 1.0.7, released with regular updates. It integrates with jsbundling-rails to replace Webpacker, providing a fast bundling experience for Rails asset pipelines. Differentiators include automatic glob resolution for importing multiple files, seamless integration with Hotwire/Stimulus, and support for jQuery via import hoisting. Requires esbuild as a peer dependency and offers both ESM and CJS configuration examples.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/excid3/esbuild-rails","tags":["javascript","esbuild","rails","stimulus","hotwire","import","glob"],"install":[{"cmd":"npm install esbuild-rails","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-rails","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-rails","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – esbuild is required as the underlying bundler.","package":"esbuild","optional":false}],"imports":[{"note":"ESM syntax recommended; CJS via require also works but may be deprecated in future.","wrong":"const rails = require('esbuild-rails')","symbol":"default","correct":"import rails from 'esbuild-rails'"},{"note":"The plugin must be called as a function, not passed as a reference.","wrong":"plugins: [rails]","symbol":"rails function","correct":"plugins: [rails()]"},{"note":"Use CJS require for the example config file if not using ES modules.","wrong":"import path from 'path' in CJS context","symbol":"Path resolution","correct":"const path = require('path'); const rails = require('esbuild-rails')"}],"quickstart":{"code":"const path = require('path');\nconst rails = require('esbuild-rails');\n\nrequire('esbuild').build({\n  entryPoints: ['application.js'],\n  bundle: true,\n  outdir: path.join(process.cwd(), 'app/assets/builds'),\n  absWorkingDir: path.join(process.cwd(), 'app/javascript'),\n  plugins: [rails()],\n}).catch(() => process.exit(1));","lang":"javascript","description":"Shows basic esbuild configuration with the rails plugin for bundling Rails JavaScript assets."},"warnings":[{"fix":"Use `rails()` (call it) instead of just `rails` in the plugins array.","message":"The plugin function must be called: `rails()` not `rails`. Passing the function reference directly will cause a build error.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use `require` for CommonJS or ensure your config file has `.mjs` extension for ESM.","message":"ESM and CJS module systems are mixed in examples – using `import` statements in a CommonJS config file may cause syntax errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Switch to `import rails from 'esbuild-rails'` with an `.mjs` config file.","message":"The `require('esbuild-rails')` pattern may be deprecated in future versions in favor of ESM imports.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Create a separate file for jQuery setup and import it at the top of your entry point.","message":"Importing jQuery via separate file relies on import hoisting; placing the import after other code may not work as expected.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to `plugins: [rails()]`.","cause":"Calling the plugin as a reference rather than invoking it: `plugins: [rails]` instead of `plugins: [rails()]`.","error":"TypeError: rails is not a function"},{"fix":"Add `plugins: [rails()]` to your esbuild build options.","cause":"Glob patterns require the esbuild-rails plugin to be active; missing plugin in esbuild config.","error":"Error: Could not resolve './src/**/*'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}