Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ProstglesClient
✓ import { ProstglesClient } from 'prostgles-client'
✗ const { ProstglesClient } = require('prostgles-client')
ESM-only import for class-based client use without React.
useProstglesClient
✓ import { useProstglesClient } from 'prostgles-client/dist/prostgles'
✗ import { useProstglesClient } from 'prostgles-client'
React hook is not exported from the main entry; must import from 'prostgles-client/dist/prostgles'.
prostgles
✓ import prostgles from 'prostgles-client'
✗ import { prostgles } from 'prostgles-client'
The standalone 'prostgles' function is the default export from the main package; named import fails.
useSync
✓ import { useSync } from 'prostgles-client/dist/prostgles'
✗ import { useSync } from 'prostgles-client'
All React hooks are only available from the subpath 'prostgles-client/dist/prostgles'.
React component using useProstglesClient hook to subscribe to published posts with real-time updates.
import { useProstglesClient } from "prostgles-client/dist/prostgles";
import { useEffect, useState } from "react";
// Define your database types (auto-generated by prostgles-server)
interface DBGeneratedSchema {
users: {
id: number;
name: string;
email: string;
};
posts: {
id: number;
title: string;
content: string;
published: boolean;
user_id: number;
};
}
function App() {
const client = useProstglesClient<DBGeneratedSchema>({
socketOptions: { path: "/ws-api" }
});
if (client.isLoading) return <div>Loading...</div>;
if (client.hasError) return <div>Error: {client.error}</div>;
return <PostsList dbo={client.dbo} />;
}
function PostsList({ dbo }: { dbo: ReturnType<typeof useProstglesClient>['dbo'] }) {
const { data: posts, isLoading } = dbo.posts.useSubscribe(
{ published: true },
{ orderBy: { created: -1 }, limit: 10 }
);
if (isLoading) return <div>Loading posts...</div>;
return (
<ul>
{posts.map(post => (
<li key={post.id}>{post.title}</li>
))}
</ul>
);
}
Errors
Common errors & fixes
Uncaught SyntaxError: The requested module 'prostgles-client' does not provide an export named 'useProstglesClient'
Importing React hooks from wrong path (main entry instead of dist/prostgles).
fixUse: import { useProstglesClient } from 'prostgles-client/dist/prostgles' Uncaught TypeError: prostgles_client_1.prostgles is not a function
Using named import { prostgles } instead of default import.
fixUse: import prostgles from 'prostgles-client'
Error: Cannot find module 'prostgles-client/dist/prostgles' or its corresponding type declarations.
Missing subpath export 'dist/prostgles' in older version or misconfigured TypeScript paths.
fixEnsure prostgles-client is at least v4.0.0 or configure moduleResolution to 'node16' or 'bundler'.
WebSocket connection to 'wss://...' failed: Error during WebSocket handshake: Unexpected response code: 400
Missing or incorrect socketOptions path; server expects specific WebSocket endpoint.
fixPass 'path' option matching your prostgles-server configuration, e.g., socketOptions: { path: '/ws-api' } Audit
Dependencies
reactoptionalPeer dependency for React hooks (useProstglesClient, useFind, useSubscribe, useSync); must be installed for React usage.
socket.io-clientoptionalRequired for WebSocket-based real-time synchronization (socket.io). Not a direct dependency but listed in installation instructions.