Hydrogen SDK: Troubleshooting
Beta SDK
These SDKs are currently in beta. APIs may change before stable release.
Common issues and solutions when using @rebuy/hydrogen-sdk.
Debug Mode
Enable debug logging to troubleshoot issues.
Server-Side Logging
Set the environment variable:
# .env
REBUY_SDK_DEBUG=true
This will output detailed logs to your server console when using getRebuyData in loaders.
Client-Side Logging
In the browser console:
window.REBUY_SDK_DEBUG = true;
This enables logging for client-side components like RecentlyViewed.
What Debug Mode Shows
- API requests and responses
- Context object being sent to Rebuy
- Cart data transformation
- Error details with stack traces
Common Issues
TypeScript Context Type Issue
If you encounter type errors with the context parameter in getRebuyData:
Type 'AppLoadContext' is not assignable to type 'RebuyLoadContext'
You may need to cast the context:
const { rebuy } = await getRebuyData({
context: context as any, // Temporary workaround for type differences
request,
});
Note
This is a known issue that will be addressed in a future version.
Products Not Updating When Cart Changes
If recommendations don't update after cart changes, ensure:
- You're using
getRebuyData in your loader (not a client component)
- The cart mutation is using Hydrogen's
<CartForm>
- You're passing the
request parameter to getRebuyData
// Correct
export async function loader({ context, request }: LoaderFunctionArgs) {
const { rebuy } = await getRebuyData({ context, request }); // ← request is required
// ...
}
Recently Viewed Not Showing Products
The RecentlyViewed component requires:
RebuyProvider is wrapping your app
RebuyProductView is on your product pages to track views
- The user has viewed at least one product
Check that RebuyProductView is correctly set up:
<RebuyProductView
product={{
id: product.id, // Must be Shopify GraphQL ID
handle: product.handle,
}}
/>
API Key Not Found
If you see "API key not found" errors:
-
Verify your .env file has the correct variable:
PUBLIC_REBUY_API_KEY=your-api-key
-
Restart your development server after adding environment variables
-
For production, ensure environment variables are configured in your hosting platform
Empty Recommendations
If API calls succeed but return empty arrays:
- Check the Data Source ID exists in your Rebuy Admin
- Verify products exist and are published in your Shopify store
- Check if "Filter Input Products" is removing all products
- Try with a simpler API call first:
const products = await rebuy.sdk.products.getTopSellers({ limit: 5 });
console.log('Products:', products);
CSP (Content Security Policy) Errors
If you see CSP errors related to inline scripts, add the nonce prop to RebuyProvider:
<RebuyProvider
apiKey={process.env.PUBLIC_REBUY_API_KEY}
nonce={yourNonceValue}
>
Getting Help
If you're still experiencing issues:
- Enable debug mode and check the console output
- Verify your API key is correct
- Test with a simple API call to isolate the problem
- Check the SDK version matches the documentation
---
title: Hydrogen SDK Troubleshooting
excerpt: Debug mode, TypeScript issues, and common problems when using @rebuy/hydrogen-sdk.
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
---
# Hydrogen SDK: Troubleshooting
!!! info "Beta SDK"
These SDKs are currently in beta. APIs may change before stable release.
Common issues and solutions when using `@rebuy/hydrogen-sdk`.
## Debug Mode
Enable debug logging to troubleshoot issues.
### Server-Side Logging
Set the environment variable:
```bash
# .env
REBUY_SDK_DEBUG=true
```
This will output detailed logs to your server console when using `getRebuyData` in loaders.
### Client-Side Logging
In the browser console:
```javascript
window.REBUY_SDK_DEBUG = true;
```
This enables logging for client-side components like `RecentlyViewed`.
### What Debug Mode Shows
- API requests and responses
- Context object being sent to Rebuy
- Cart data transformation
- Error details with stack traces
## Common Issues
### TypeScript Context Type Issue
If you encounter type errors with the context parameter in `getRebuyData`:
```
Type 'AppLoadContext' is not assignable to type 'RebuyLoadContext'
```
You may need to cast the context:
```tsx
const { rebuy } = await getRebuyData({
context: context as any, // Temporary workaround for type differences
request,
});
```
!!! note
This is a known issue that will be addressed in a future version.
### Products Not Updating When Cart Changes
If recommendations don't update after cart changes, ensure:
1. You're using `getRebuyData` in your loader (not a client component)
2. The cart mutation is using Hydrogen's `<CartForm>`
3. You're passing the `request` parameter to `getRebuyData`
```tsx
// Correct
export async function loader({ context, request }: LoaderFunctionArgs) {
const { rebuy } = await getRebuyData({ context, request }); // ← request is required
// ...
}
```
### Recently Viewed Not Showing Products
The `RecentlyViewed` component requires:
1. `RebuyProvider` is wrapping your app
2. `RebuyProductView` is on your product pages to track views
3. The user has viewed at least one product
Check that `RebuyProductView` is correctly set up:
```tsx
<RebuyProductView
product={{
id: product.id, // Must be Shopify GraphQL ID
handle: product.handle,
}}
/>
```
### API Key Not Found
If you see "API key not found" errors:
1. Verify your `.env` file has the correct variable:
```bash
PUBLIC_REBUY_API_KEY=your-api-key
```
2. Restart your development server after adding environment variables
3. For production, ensure environment variables are configured in your hosting platform
### Empty Recommendations
If API calls succeed but return empty arrays:
1. Check the Data Source ID exists in your Rebuy Admin
2. Verify products exist and are published in your Shopify store
3. Check if "Filter Input Products" is removing all products
4. Try with a simpler API call first:
```tsx
const products = await rebuy.sdk.products.getTopSellers({ limit: 5 });
console.log('Products:', products);
```
### CSP (Content Security Policy) Errors
If you see CSP errors related to inline scripts, add the `nonce` prop to `RebuyProvider`:
```tsx
<RebuyProvider
apiKey={process.env.PUBLIC_REBUY_API_KEY}
nonce={yourNonceValue}
>
```
## Getting Help
If you're still experiencing issues:
1. Enable debug mode and check the console output
2. Verify your API key is correct
3. Test with a simple API call to isolate the problem
4. Check the SDK version matches the documentation
## Related
- [Getting Started](hydrogen-sdk-getting-started.md) - Installation and setup
- [Implementation Patterns](hydrogen-sdk-implementation.md) - Server vs client rendering
- [Components & Hooks](hydrogen-sdk-components.md) - Component reference