Glitch JavaScript SDK
raw JSON → 3.0.6 verified Sat May 09 auth: no javascript
Official JavaScript SDK for Glitch, an open-source live community platform for gaming and esports. Version 3.0.6 is current stable. Released as needed; key differentiator is its tight integration with the Glitch backend API. Supports both browser and Node.js environments. Includes TypeScript definitions.
Common errors
error Uncaught TypeError: Glitch.config is undefined ↓
cause Using named imports instead of default import of Glitch object.
fix
Use: import Glitch from 'glitch-javascript-sdk';
error ERR_REQUIRE_ESM ↓
cause Using require() to import an ESM-only package.
fix
Convert to import syntax or use dynamic import().
error TypeError: Cannot read properties of undefined (reading 'setBaseUrl') ↓
cause Calling Glitch.config.Config.setBaseUrl before initializing Glitch (e.g., using wrong import).
fix
Ensure you import Glitch correctly as default and then call Glitch.config.Config.setBaseUrl.
Warnings
breaking v3.0.0 changed to ESM-only; CommonJS require() will fail without module transformation. ↓
fix Use import syntax or enable ESM compat in your bundler (e.g., 'type': 'module' in package.json).
deprecated Glitch.api.Auth.register has been deprecated in v3.0.0; use Glitch.api.Users.create ↓
fix Replace Glitch.api.Auth.register with Glitch.api.Users.create.
gotcha Config setBaseUrl second parameter 'addTrailingSlash' defaults to false in v2.x, true in v3.x ↓
fix Explicitly pass true to ensure consistent trailing slash behavior.
gotcha Setting auth token before base URL may cause requests to fail silently ↓
fix Always call setBaseUrl before setAuthToken.
Install
npm install glitch-javascript-sdk yarn add glitch-javascript-sdk pnpm add glitch-javascript-sdk Imports
- Glitch wrong
const Glitch = require('glitch-javascript-sdk')correctimport Glitch from 'glitch-javascript-sdk' - Glitch.config.Config wrong
import { Config } from 'glitch-javascript-sdk'correctimport Glitch from 'glitch-javascript-sdk'; Glitch.config.Config.setBaseUrl(url) - Glitch.api.Auth wrong
import { Auth } from 'glitch-javascript-sdk'correctimport Glitch from 'glitch-javascript-sdk'; Glitch.api.Auth.login(email, password)
Quickstart
import Glitch from 'glitch-javascript-sdk';
Glitch.config.Config.setBaseUrl('https://api.glitch.local/api/', true);
const jwt = process.env.JWT ?? '';
if (jwt) {
Glitch.config.Config.setAuthToken(jwt);
}
Glitch.api.Auth.login('user@example.com', 'password123')
.then(() => console.log('Logged in'))
.catch(err => console.error(err));
// Use other API endpoints
Glitch.api.Users.getCurrentUser().then(user => console.log(user));