Packaging & Bundlers

Use praisonai in Node, browsers, React Native, and edge runtimes

praisonai ships both ESM and CommonJS builds, so it works out-of-the-box with modern bundlers and legacy Node projects alike.

Diagram

praisonai package

📦 Source

🔨 Build

⚙️ CJS
dist/index.js

⚡ ESM
dist/esm/index.js

🟢 Node
require

🌐 Bundlers
Vite / Webpack / Metro

📘 TS / ESM App
import

Quick Start

  1. Install
    npm
    npm install praisonai
    yarn
    yarn add praisonai
  2. Create an agent (ESM or CommonJS)

    ESM

    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
    agent.start('Write a movie script about a robot in Mars');

    CommonJS

    javascript
    const { Agent } = require('praisonai');
    
    const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
    agent.start('Write a movie script about a robot in Mars');

How It Works

The package.json entry points tell each runtime and bundler which build to load.

Diagram

import

dist/esm/index.js

require

dist/index.js

TypeScript

dist/index.d.ts

import resolves to the ESM build, require resolves to the CJS build, and TypeScript reads the shared type declarations — no configuration needed on your side.

FieldValueWhat it does
maindist/index.jsCommonJS entry for require
moduledist/esm/index.jsHints bundlers at the ESM build
typesdist/index.d.tsTypeScript declarations
exports["."].import./dist/esm/index.jsESM entry for import
exports["."].require./dist/index.jsCJS entry for require

The ESM build is produced by a small shim that rewrites relative specifiers, adds a createRequire banner for interop, and drops a dist/esm/package.json marked { "type": "module" }.


Using in Different Environments

Pick the entry point that matches where you run praisonai.

Diagram

Node.js server

Browser / React Native

Edge / Deno / Bun

type: module

CommonJS

Where are you using praisonai?

Runtime?

ESM or CJS project?

Use deep imports
praisonai/agent/simple
Agent + types

Use ESM entry
import from ‘praisonai’

Use require
const Agent = require’praisonai’

Node.js (CommonJS)

javascript
const { Agent } = require('praisonai');

const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a haiku about the ocean');

Node.js (ESM)

typescript
import { Agent } from 'praisonai';

const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a haiku about the ocean');

TypeScript

tsconfig.json
{
  "compilerOptions": {
    "module": "esnext",
    "moduleResolution": "bundler",
    "target": "es2022"
  }
}
app.ts
import { Agent } from 'praisonai';

const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Explain quantum computing simply');

Vite / Rollup / esbuild

typescript
import { Agent } from 'praisonai';

const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
await agent.start('Summarise the latest AI news');

Next.js

app/api/agent/route.ts
import { Agent } from 'praisonai';

export async function POST(req: Request) {
  const { prompt } = await req.json();
  const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
  const result = await agent.start(prompt);
  return Response.json({ result });
}

React Native (Metro)

typescript
import { Agent } from 'praisonai/agent/simple';

const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Suggest a name for my app');

Deno / Bun

typescript
import { Agent } from 'praisonai';

const agent = new Agent({ instructions: 'You are a helpful AI assistant' });
agent.start('Write a limerick about coffee');

Subpath Imports

Import from a subpath to load only the module you need.

Root barrel
import { Agent, Agents } from 'praisonai';
AI primitives
import { generateText, streamText } from 'praisonai/ai';
Tools
import { createTool, tool } from 'praisonai/tools';
Deep import
import { Agent } from 'praisonai/agent/simple';
SubpathImportContents
.praisonaiFull public API (Agent, Agents, Workflow, tools, providers)
./aipraisonai/aiAI SDK wrappers (generateText, streamText, generateObject)
./toolspraisonai/toolsTool base classes and registry (createTool, tool)
./agent/simplepraisonai/agent/simpleThe Agent class plus agent-related type exports (SimpleAgentConfig, AgentTeamConfig, PraisonAIAgentsConfig). The team-class values (AgentTeam, PraisonAIAgents, Agents) are not re-exported here — import those from praisonai or praisonai/agent.

Best Practices

Prefer ESM imports in new projects

Use import { Agent } from 'praisonai' for new code. ESM is the default for bundlers and edge runtimes, and it preserves await import() as a lazy chunk instead of forcing a synchronous require().

Bundle for the browser today — what works and what doesn't

The root barrel (praisonai) still pulls in the CLI and other Node-only code, so a raw import 'praisonai' in a browser or React Native bundle drags in Node built-ins. Use deep imports — for example praisonai/agent/simple — to keep browser and React Native bundles Node-safe.

Verify your install with verify:dist

Contributors can run npm run verify:dist to confirm both the CJS and ESM entry points load in a real Node process before publishing.

Node version — 18 or later

The package sets engines.node >= 18. The bundled openai dependency needs Node 18, so older runtimes are not supported.


Related