{"id":18090,"library":"actioncable","title":"Action Cable","description":"Action Cable is the WebSocket framework integrated into Ruby on Rails, providing real-time communication capabilities for Rails applications. The npm package 'actioncable' (current stable version 5.2.8-1, though the Rails ecosystem recommends using the latest 7.x or 8.x series) is the JavaScript client library that connects to an Action Cable server. It allows developers to subscribe to channels and receive broadcasts in the browser or any JavaScript runtime. Key differentiators: tight integration with Rails (session/cookie-based authentication, same MVC patterns), full-stack offering with both server- and client-side components, and pub-sub streaming model. Release cadence follows Rails releases, with frequent minor and patch updates. Alternatives include pure WebSocket libraries or Pusher, but Action Cable is the default for Rails real-time features.","status":"active","version":"5.2.8-1","language":"javascript","source_language":"en","source_url":"https://github.com/rails/rails","tags":["javascript","websockets","actioncable","rails"],"install":[{"cmd":"npm install actioncable","lang":"bash","label":"npm"},{"cmd":"yarn add actioncable","lang":"bash","label":"yarn"},{"cmd":"pnpm add actioncable","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import works with both ESM and CJS environments. For TypeScript, use `import ActionCable from 'actioncable'` with esModuleInterop enabled.","wrong":"const ActionCable = require('actioncable')","symbol":"ActionCable","correct":"import ActionCable from 'actioncable'"},{"note":"Named export available since v5.2.0. Prefer over default import for tree-shaking.","wrong":"import { createConsumer } from '@rails/actioncable'","symbol":"createConsumer","correct":"import { createConsumer } from 'actioncable'"},{"note":"Consumer is a TypeScript interface, not a class. Use type import to avoid runtime errors.","wrong":"import { Consumer } from 'actioncable'","symbol":"Consumer","correct":"import type { Consumer } from 'actioncable'"},{"note":"Utility function for building WebSocket URLs. Import directly from package root.","wrong":"import { createWebSocketURL } from 'actioncable/lib'","symbol":"createWebSocketURL","correct":"import { createWebSocketURL } from 'actioncable'"}],"quickstart":{"code":"import ActionCable from 'actioncable';\n\nconst cable = ActionCable.createConsumer('ws://localhost:3000/cable');\nconst subscription = cable.subscriptions.create('ChatChannel', {\n  connected() {\n    console.log('Connected to ChatChannel');\n  },\n  disconnected() {\n    console.log('Disconnected');\n  },\n  received(data) {\n    console.log('Received:', data);\n  }\n});\n\n// Send data to server (requires server-side handling)\nsubscription.send({ message: 'Hello!' });\n\n// Unsubscribe when done\nsubscription.unsubscribe();\ncable.disconnect();","lang":"typescript","description":"Shows how to create a consumer, subscribe to a channel, handle lifecycle events, send data, and clean up."},"warnings":[{"fix":"Pass a string URL or call without arguments to use the default from meta tags.","message":"ActionCable.createConsumer() no longer accepts a function as argument; must pass a URL string or omit for default.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use import from 'actioncable' instead of '@rails/actioncable'. Both publish the same code, but actioncable is the canonical name.","message":"The package @rails/actioncable (npm) is deprecated in favor of the actioncable package (npm).","severity":"deprecated","affected_versions":">=5.2.0"},{"fix":"Install 'ws' package and set global.WebSocket = require('ws'); or use a bundler that polyfills WebSocket.","message":"Importing 'actioncable' in Node.js without a WebSocket polyfill will throw: 'WebSocket is not defined'.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Run 'npm install --save-dev @types/actioncable' to get type definitions.","message":"TypeScript definitions are not included; you must install @types/actioncable separately.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Use the top-level API: ActionCable.createConsumer() and subscription methods.","message":"ActionCable.Connection and ActionCable.Subscription are no longer publicly accessible; use createConsumer and subscriptions.create.","severity":"breaking","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":"Install the 'ws' package and add: global.WebSocket = require('ws'); before importing ActionCable.","cause":"Running in Node.js environment where WebSocket is not globally available.","error":"WebSocket is not defined"},{"fix":"Change import to 'actioncable'.","cause":"Importing from deprecated package name @rails/actioncable.","error":"Module not found: Can't resolve '@rails/actioncable'"},{"fix":"Use import ActionCable from 'actioncable' for default import, and ensure the version is >=5.0.0.","cause":"Using the wrong import (e.g., importing default incorrectly or using a very old version).","error":"TypeError: ActionCable.createConsumer is not a function"},{"fix":"Install @types/actioncable as a devDependency: npm install --save-dev @types/actioncable.","cause":"TypeScript cannot find type definitions.","error":"Cannot find module 'actioncable' or its corresponding type declarations."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}