{"id":47282,"library":"cometd","title":"CometD","description":"CometD is a scalable comet and WebSocket messaging library for web applications, providing publish/subscribe, RPC, and peer-to-peer communication patterns. The current stable version is 9.0.0, released under the Apache 2.0 license. It ships TypeScript types and supports ES modules. CometD replaces the older cometd-jQuery and provides a modern, promise-based API. It differentiates from alternatives like Socket.IO by being more lightweight and focusing on the Bayeux protocol with built-in support for long-polling, WebSocket, and extensions like time-stamping.","status":"active","version":"9.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/cometd/cometd-javascript","tags":["javascript","comet","websocket","messaging","pubsub","publish","subscribe","rpc","p2p","typescript"],"install":[{"cmd":"npm install cometd","lang":"bash","label":"npm"},{"cmd":"yarn add cometd","lang":"bash","label":"yarn"},{"cmd":"pnpm add cometd","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS require is not supported in the ES module distribution. Use named import.","wrong":"const CometD = require('cometd').CometD","symbol":"CometD","correct":"import { CometD } from 'cometd'"},{"note":"TimeStampExtension is a named export, not default. Use named import syntax.","wrong":"import TimeStampExtension from 'cometd/TimeStampExtension'","symbol":"TimeStampExtension","correct":"import { TimeStampExtension } from 'cometd/TimeStampExtension'"},{"note":"There is no default export; always use named imports.","wrong":"import CometD from 'cometd'","symbol":"default import (assuming no default export)","correct":"import { CometD } from 'cometd'"}],"quickstart":{"code":"import { CometD } from 'cometd';\nimport { TimeStampExtension } from 'cometd/TimeStampExtension';\n\nconst cometd = new CometD();\ncometd.registerExtension('timestamp', new TimeStampExtension());\ncometd.configure({ url: process.env.COMETD_URL ?? 'http://localhost:8080/cometd' });\ncometd.handshake((reply) => {\n  if (reply.successful) {\n    console.log('Handshake succeeded');\n    cometd.subscribe('/topic', (message) => {\n      console.log('Received message:', message.data);\n    });\n  }\n});","lang":"typescript","description":"Initializes a CometD client, registers a time-stamp extension, configures the URL, performs a handshake, and subscribes to a topic."},"warnings":[{"fix":"Ensure your runtime supports ES modules (Node >=13.2 or modern browser). Use import/export syntax.","message":"Version 9 drops support for older browser APIs and requires ES module environment.","severity":"breaking","affected_versions":">=9.0.0"},{"fix":"Use the core CometD library without jQuery. Migrate any jQuery-specific extensions.","message":"The cometd-jQuery integration module is deprecated and removed in v9.","severity":"deprecated","affected_versions":">=9.0.0"},{"fix":"Switch to ES module imports: import { CometD } from 'cometd'.","message":"CommonJS require() no longer works starting from v8.0.0.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Use correct path like 'cometd/TimeStampExtension' not 'cometd/timestamp'.","message":"Import paths for extensions are case-sensitive and must use forward slashes.","severity":"gotcha","affected_versions":">=8.0.0"}],"env_vars":null,"search_vec":"'2.0':34 '9.0.0':29 'altern':62 'apach':33 'api':58 'applic':13 'base':57 'bayeux':73 'built':77 'built-in':76 'comet':6,92 'cometd':1,2,44,49 'cometd-jqueri':48 'communic':22 'current':25 'differenti':60 'es':42 'extens':86 'focus':70 'javascript':91 'jqueri':50 'librari':10 'licens':35 'lightweight':68 'like':63,87 'long':82 'long-pol':81 'messag':9,94 'modern':54 'modul':43 'older':47 'p2p':99 'pattern':23 'peer':19,21 'peer-to-p':18 'poll':83 'promis':56 'promise-bas':55 'protocol':74 'provid':14,52 'publish':96 'publish/subscribe':15 'pubsub':95 'releas':30 'replac':45 'rpc':16,98 'scalabl':5 'ship':37 'socket.io':64 'stabl':26 'stamp':90 'subscrib':97 'support':41,79 'time':89 'time-stamp':88 'type':39 'typescript':38,100 'version':27 'web':12 'websocket':8,84,93","created_at":"2026-06-07T16:50:43.939261+00:00","updated_at":"2026-06-07T16:50:43.939261+00:00","problems":[{"fix":"Use named import: import { CometD } from 'cometd';","cause":"CometD object not properly imported (default import used instead of named import).","error":"Uncaught TypeError: cometd.configure is not a function"},{"fix":"Install package via npm install cometd and ensure using ES module syntax.","cause":"Package not installed or import path incorrect in CommonJS environment.","error":"Cannot find module 'cometd'"},{"fix":"Configure server to serve .js files with MIME type application/javascript or text/javascript.","cause":"Server misconfigured to serve .js files with incorrect MIME type for ES modules.","error":"Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://cometd.org","github":"https://github.com/cometd/cometd-javascript","docs":null,"changelog":null,"pypi":null,"npm":"cometd","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}