Registry / web-framework / actioncable

actioncable

JSON →
library0.2.0jsnpmunverified

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.

npm install actioncable
INSTALL
IMPORT
SIG · ACTIONCABLE
A
actioncable
web-frameworkjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ActionCable
import ActionCable from 'actioncable'
const ActionCable = require('actioncable')
Default import works with both ESM and CJS environments. For TypeScript, use `import ActionCable from 'actioncable'` with esModuleInterop enabled.
createConsumer
import { createConsumer } from 'actioncable'
import { createConsumer } from '@rails/actioncable'
Named export available since v5.2.0. Prefer over default import for tree-shaking.
Consumer
import type { Consumer } from 'actioncable'
import { Consumer } from 'actioncable'
Consumer is a TypeScript interface, not a class. Use type import to avoid runtime errors.
createWebSocketURL
import { createWebSocketURL } from 'actioncable'
import { createWebSocketURL } from 'actioncable/lib'
Utility function for building WebSocket URLs. Import directly from package root.

Shows how to create a consumer, subscribe to a channel, handle lifecycle events, send data, and clean up.

import ActionCable from 'actioncable'; const cable = ActionCable.createConsumer('ws://localhost:3000/cable'); const subscription = cable.subscriptions.create('ChatChannel', { connected() { console.log('Connected to ChatChannel'); }, disconnected() { console.log('Disconnected'); }, received(data) { console.log('Received:', data); } }); // Send data to server (requires server-side handling) subscription.send({ message: 'Hello!' }); // Unsubscribe when done subscription.unsubscribe(); cable.disconnect();
Debug
Known issues
breakingActionCable.createConsumer() no longer accepts a function as argument; must pass a URL string or omit for default.
fix
Pass a string URL or call without arguments to use the default from meta tags.
affects: >=5.0.0
deprecatedThe package @rails/actioncable (npm) is deprecated in favor of the actioncable package (npm).
fix
Use import from 'actioncable' instead of '@rails/actioncable'. Both publish the same code, but actioncable is the canonical name.
affects: >=5.2.0
gotchaImporting 'actioncable' in Node.js without a WebSocket polyfill will throw: 'WebSocket is not defined'.
fix
Install 'ws' package and set global.WebSocket = require('ws'); or use a bundler that polyfills WebSocket.
affects: >=5.0.0
gotchaTypeScript definitions are not included; you must install @types/actioncable separately.
fix
Run 'npm install --save-dev @types/actioncable' to get type definitions.
affects: >=5.0.0
breakingActionCable.Connection and ActionCable.Subscription are no longer publicly accessible; use createConsumer and subscriptions.create.
fix
Use the top-level API: ActionCable.createConsumer() and subscription methods.
affects: >=5.0.0
Errors
Common errors & fixes
WebSocket is not defined
Running in Node.js environment where WebSocket is not globally available.
fix
Install the 'ws' package and add: global.WebSocket = require('ws'); before importing ActionCable.
Module not found: Can't resolve '@rails/actioncable'
Importing from deprecated package name @rails/actioncable.
fix
Change import to 'actioncable'.
TypeError: ActionCable.createConsumer is not a function
Using the wrong import (e.g., importing default incorrectly or using a very old version).
fix
Use import ActionCable from 'actioncable' for default import, and ensure the version is >=5.0.0.
Cannot find module 'actioncable' or its corresponding type declarations.
TypeScript cannot find type definitions.
fix
Install @types/actioncable as a devDependency: npm install --save-dev @types/actioncable.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
53 hits · last 30 days
node
46
OpenAI (training)
1
Resources
actioncable — npm install actioncable · libregistry