stripe-js
The official ES/CommonJS loader for Stripe.js and Stripe Elements
Repository Health
Technical Analysis
@stripe/stripe-js is the official loading wrapper that lets you import Stripe.js as an ES module or CommonJS module instead of relying on a hand-written script tag. It exposes a single loadStripe helper that returns a promise resolving to a fully initialized Stripe object, handling script injection, version pinning, and PCI-compliant loading from js.stripe.com for you.
Because Stripe.js must be served directly from Stripe’s domain to stay PCI compliant, this package never bundles the payment library itself — it wraps the global Stripe constructor and ships TypeScript definitions that track the latest Stripe API. That makes it the standard entry point for adding Stripe Elements, Payment Intents, and advanced fraud detection to any modern JavaScript or TypeScript web application.
What You Get
- A promise-based
loadStripe(publishableKey)helper that resolves to an initialized Stripe object - Automatic insertion of the Stripe.js script tag from js.stripe.com, with reuse of any existing tag
- A side-effect-free
@stripe/stripe-js/pureentry point for deferred loading and load-parameter control - Bundled TypeScript definitions that track the latest Stripe API and Elements
- Server-side safety —
loadStriperesolves to null when called outside the browser
Common Use Cases
- Mounting Stripe Elements to collect card and payment details in a React, Vue, or vanilla web app
- Confirming Payment Intents and Setup Intents on the client during checkout
- Enabling Stripe’s advanced fraud detection by loading Stripe.js on every page
- Deferring Stripe.js loading until checkout to minimize third-party requests on other pages
Under The Hood
Architecture
The package is a small, single-purpose loader split across three source files in src/. shared.ts holds the core: loadScript guards a module-level stripePromise singleton so Stripe.js is fetched at most once, calling findScript/injectScript to reuse or create a <script src="https://js.stripe.com/..."> tag and wiring load/error listeners that resolve to window.Stripe; initStripe then validates the publishable key, compares the runtime release train, and calls _registerWrapper for telemetry. index.ts is the default entry that eagerly kicks off loadScript on import (after a microtask) so the tag lands early, while pure.ts is the deferred variant that only loads on the first loadStripe call and adds setLoadParameters.
Tech Stack
Written almost entirely in TypeScript (~92%), the package has zero runtime dependencies and is built with Rollup (rollup.config.js) plus Babel to emit both CommonJS (lib/index.js) and ES module (lib/index.mjs) bundles, with @rollup/plugin-replace inlining the package version into _VERSION. Type declarations live under types/ and are copied into the published output. Tooling includes ESLint, Prettier, and @arethetypeswrong/cli for package-export correctness, targeting Node >= 12.16 and TypeScript >= 3.1.
Code Quality
Code quality is high for a library this size. Each source module has a colocated Jest test (index.test.ts, pure.test.ts, shared.test.ts) and the test script chains unit tests, type-snapshot tests, are-the-types-wrong checks, and tsc typechecking. Error handling is explicit and user-facing — clear thrown Error messages for invalid keys and load parameters, a cause-wrapped ‘Failed to load Stripe.js’ rejection, and cache reset on failure so a retry can re-inject the script. Naming is consistent and the public surface is deliberately tiny.
API Design
The developer experience is excellent: the entire public API is essentially loadStripe(publishableKey) returning a typed promise, which removes nearly all boilerplate compared with hand-managing a script tag. The /pure entry point and setLoadParameters give an escape hatch for deferred loading and fraud-signal control without complicating the common path, and isomorphic safety (resolving to null on the server) means the same import works in SSR. Documentation in the README is thorough, with runnable examples and an examples/ directory.
Used by 45 apps in this directory
PostHog
Ab Testing Experimentation · Analytics · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
Postiz
Automation · Social Media
The agentic social media scheduler — AI-powered content creation, 33-platform posting, and team workflows, all self-hosted.
Rybbit
Analytics
Open-source, privacy-friendly web and product analytics with cookieless tracking, session replays, funnels, and real-time dashboards — a self-hostable alternative to Google Analytics.
Sentry
Analytics · Developer Tools · Monitoring
Developer-first error tracking and performance monitoring platform with AI-powered root-cause analysis across 20+ languages and frameworks.
Hexclave
Authentication · Developer Tools
The open-source user infrastructure platform — authentication, teams, payments, emails, analytics, and more on a single unified user model.
Stirling PDF
Digital Signiture · Productivity
The open-source PDF platform you can run anywhere — edit, convert, sign, and automate PDFs without sending files to external servers.
Supabase
Authentication · Databases · Developer Tools
The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.
twenty
CRM
The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.
Typebot
AI Assistants · AI Development · Developer Tools
Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.