xiaohongshu
xiaohongshu
esm-cjs-interop
Handle ESM/CJS module interoperability in the Orient monorepo. Use when encountering import errors, circular dependencies, module resolution issues, or "does not provide an export named" errors. Covers import patterns, re-export strategies, and avoiding circular dependency chains.
Full skill instructions
# Check if package is ESM or CJS
grep '"type"' packages/*/package.json
# Find circular dependency issues
npx madge --circular packages/*/src/index.ts
This monorepo uses ESM ("type": "module") for all packages:
// packages/*/package.json
{
"type": "module",
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
However, some legacy code in src/ may still use CJS patterns, creating interop issues.
ESM requires explicit .js extensions in import paths, even for TypeScript files:
// ✅ Correct - explicit .js extension
import { loadConfig } from './config/index.js';
import { createLogger } from '@orientbot/core';
// ❌ Wrong - missing extension (works in CJS, fails in ESM)
import { loadConfig } from './config/index';
This error occurs when CJS modules are re-exported incorrectly in ESM:
Error: The requested module '@orientbot/package' does not provide
an export named 'SomeClass'
// ❌ Wrong - doesn't work with CJS modules
export * from './some-cjs-module.js';
export { SomeClass } from './some-cjs-module.js';
// ✅ Correct - use default import first
import SomeCjsModule from './some-cjs-module.js';
export const { SomeClass, someFunction } = SomeCjsModule;
// Or re-export the whole module
export default SomeCjsModule;
Circular dependencies cause runtime failures, especially when ESM and CJS mix.
@orientbot/mcp-tools
└── imports @orientbot/agents (to get PromptService)
└── imports @orientbot/mcp-tools (for tool definitions)
└── CIRCULAR!
Instead of importing a high-level package that re-exports, import the specific lower-level package:
// ❌ Creates circular dependency
import { PromptService } from '@orientbot/agents';
// ✅ Import the actual implementation package
import { MessageDatabase } from '@orientbot/database-services';
// Use MessageDatabase.setSystemPrompt directly
# Check for circular dependencies
npx madge --circular --extensions ts packages/*/src/index.ts
# Visualize dependency graph
npx madge --image deps.svg packages/mcp-tools/src/index.ts
Follow this dependency direction to avoid cycles:
┌─────────────────────────────────────────────────┐
│ Allowed Import Direction │
│ │
│ @orientbot/core │
│ ↓ │
│ @orientbot/database │
│ ↓ │
│ @orientbot/database-services │
│ ↓ │
│ @orientbot/integrations │
│ ↓ │
│ @orientbot/agents │
│ ↓ │
│ @orientbot/mcp-tools │
│ ↓ │
│ @orientbot/bot-whatsapp | @orientbot/bot-slack │
└─────────────────────────────────────────────────┘
Packages can only import from packages above them in this hierarchy.
// packages/*/src/index.ts
// Re-export types (always safe)
export type { ConfigOptions, LogLevel } from './types/index.js';
// Re-export ESM modules
export { loadConfig } from './config/index.js';
export { createLogger } from './logger/index.js';
// Re-export default exports
export { default as SomeClass } from './SomeClass.js';
Use package.json exports field for dual support:
{
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
}
}
}
Tests may use different module resolution (esbuild/vite transforms). Check:
export * with a CJS module?# Ensure dist/ exists
ls packages/*/dist/
# Rebuild the package
pnpm --filter @orientbot/package-name build
# Check exports in package.json match dist/ structure
When importing CJS modules dynamically:
// ESM dynamic import of CJS module
const cjsModule = await import('./cjs-module.cjs');
const { someExport } = cjsModule.default || cjsModule;
.js extensions in all import pathsexport * with modules that might be CJSxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience