@maximai/maxim-js
SDK in both Node.js and React Native projects.
Table of Contents
Node.js Setup
Installation
Basic Configuration
Environment Variables
Create a.env
file in your project root:
Example Usage
React Native Setup
Installation
Required Polyfills
Install the necessary Node.js polyfills for React Native:Metro Configuration
Create or update yourmetro.config.js
file:
Service Layer Setup
Create a service layer to handle SDK initialization and exports:Environment Variables
For Expo projects, create a.env
file:
React Native Component Example
Usage Examples
Working with Prompts
Working with Datasets
Variable Types
The SDK provides several variable types:Troubleshooting
Common Issues
1. Node.js Module Import Errors in React Native
Error:The package attempted to import the Node standard library module "os"
Solution: Ensure you have installed all required polyfills and configured Metro correctly as shown in the React Native Setup section.
2. VariableType Import Issues in React Native
Error: Runtime crashes when importing VariableType directly Solution: Use the service layer approach to load VariableType asynchronously:3. Metro Bundling Issues
Error: Metro fails to resolve modules Solution:- Clear Metro cache:
npx expo start --clear
- Ensure all polyfills are installed
- Verify
metro.config.js
is properly configured
4. API Key Issues
Error: Authentication failures Solution:- Verify your API key is correct
- For React Native/Expo, use
EXPO_PUBLIC_
prefix for environment variables - For Node.js, use standard environment variables
Best Practices
- Always initialize the SDK before making API calls
- Use the service layer in React Native projects for better error handling
- Handle errors gracefully with try-catch blocks
- Load VariableType asynchronously in React Native
- Clear Metro cache when adding new polyfills
Support
For additional support:- Visit Maxim AI Documentation
- Check the GitHub repository for updates
Changelog
Version Compatibility
@maximai/maxim-js
v6.15.0+: Supports both Node.js and React Native with proper configuration- React Native: Requires Metro configuration and polyfills
- Node.js: Works out of the box
Recent Updates
- Added comprehensive React Native support
- Improved platform detection
- Enhanced error handling
- Added TypeScript definitions