Skip to main content
This guide covers how to set up the @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 your metro.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:
  1. Clear Metro cache: npx expo start --clear
  2. Ensure all polyfills are installed
  3. 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

  1. Always initialize the SDK before making API calls
  2. Use the service layer in React Native projects for better error handling
  3. Handle errors gracefully with try-catch blocks
  4. Load VariableType asynchronously in React Native
  5. Clear Metro cache when adding new polyfills

Support

For additional support:

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