Strophe.js is published to npm asDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/strophe/strophejs/llms.txt
Use this file to discover all available pages before exploring further.
strophe.js and ships a single package with multiple distribution formats — an ES module bundle, a CommonJS bundle, a Node.js-specific ESM build, and a UMD browser bundle. You can install it with any Node.js package manager, load it from a CDN for quick prototyping, or drop the UMD file directly into a <script> tag. The sections below walk through each path.
Install via Package Manager
Install peer dependencies (Node.js only)
When running in Node.js, the browser-native WebSocket and DOM APIs are not available. Strophe.js declares
jsdom and ws as optional peer dependencies to fill this gap:ws— a WebSocket client/server implementation for Node.js, used by theWebsocketandWorkerWebsockettransports.jsdom— a full DOM implementation for Node.js, used for XML parsing and stanza construction.
Import the library
Add the import to your source file. All public exports are available from the top-level See the Import Examples section below for the full list of named exports and the equivalent CommonJS
strophe.js specifier:require syntax.Package Entry Points
Thepackage.json defines separate entry points so bundlers and runtimes automatically receive the right format:
| Field | File | Used by |
|---|---|---|
module | dist/strophe.esm.js | Browser ESM bundlers (Vite, Rollup, webpack) |
browser (require) | dist/strophe.umd.cjs | Browser CJS bundlers |
main (node) | dist/strophe.cjs | Node.js require() |
node (import) | dist/strophe.node.esm.js | Node.js import |
unpkg / CDN | dist/strophe.umd.min.js | <script> tags, CDN |
types | dist/types/index.d.ts | TypeScript compiler |
exports map in package.json routes import/require calls to the correct file based on the environment automatically.
Import Examples
- Browser (ESM)
- Node.js (ESM)
- Node.js (CJS)
- Browser (CDN / UMD)
Modern bundlers targeting browsers resolve the All of
module entry point. Import the named exports you need:$build, $msg, $iq, $pres, Strophe, and stx are also registered on globalThis by the library, so they are available as globals in browser environments without an explicit import.TypeScript Support
TypeScript type declarations are generated from the source and placed atdist/types/index.d.ts. The types field in package.json points there, so no @types/strophe.js package is needed — types are resolved automatically when you add strophe.js to your project.
Strophe.js v4.1 will complete the migration to full TypeScript source. Type definitions were first introduced in v2.0 via JSDoc annotations and generated type declaration files. If you are on an older version and see missing types, upgrade to v2.0 or later.