Requirements
- Node.js 18+ (for Node.js environments)
- Modern browser (for browser environments)
- TypeScript 4+ (optional, for TypeScript projects)
Installation
Install vij-sdk using your preferred package manager:Basic Setup
Browser Applications
For vanilla JavaScript, React, Vue, Svelte, or any browser-based framework:Node.js Applications
For Express, Fastify, or any Node.js backend:Next.js Applications
Next.js requires special handling for App Router vs Pages Router:- App Router
- Pages Router
- Server-Side (API Routes)
Create a client component for SDK initialization:Then import in your root layout:Add environment variable to
lib/vij.js
app/layout.js
.env.local:TypeScript Setup
vij-sdk includes full TypeScript definitions out of the box. No additional@types package needed!
example.ts
Verification
After installation, verify that VIJ is working:Check your VIJ Admin dashboard at
/logs — you should see the test message appear within a few seconds.Module Formats
vij-sdk is distributed in multiple formats for maximum compatibility:- ESM (
dist/index.mjs) - Modern JavaScript modules - CommonJS (
dist/index.cjs) - Legacy Node.js require() - TypeScript (
dist/index.d.ts) - Type definitions
exports field ensures the correct format is used automatically.
Bundle Size
vij-sdk is designed to be lightweight:- Minified: ~8KB
- Gzipped: ~3KB
- Zero dependencies (except tslib for TypeScript helpers)
Troubleshooting
Module not found error
Module not found error
Issue:
Cannot find module 'vij-sdk'Solution:- Ensure you ran
npm install vij-sdk - Check that node_modules/vij-sdk exists
- Try deleting node_modules and running install again
- For Yarn/PNPM, ensure the package is in your lock file
SDK not capturing errors
SDK not capturing errors
Issue: Errors not appearing in dashboardSolution:
- Verify
init()is called before any other code - Check that
endpointURL is correct and accessible - Look for CORS errors in browser console
- Ensure your VIJ Admin instance is running
- Check Network tab for failed POST requests to /api/logs
TypeScript errors
TypeScript errors
Issue: Type errors or missing IntelliSenseSolution:
- Ensure TypeScript 4+ is installed
- Check that
node_modules/vij-sdk/dist/index.d.tsexists - Try restarting your IDE/TypeScript server
- Verify
moduleResolutionin tsconfig.json is set to “bundler” or “node16”
Next.js: window is not defined
Next.js: window is not defined
Issue: ReferenceError: window is not definedSolution:
- Wrap init() in
typeof window !== "undefined"check - Use
"use client"directive for App Router components - See Next.js setup examples above