Fast SWC-powered build tool that compiles TypeScript/JavaScript to dual ESM/CommonJS packages. Solve the dual package hazard and ship modern packages with ease.
Publishing JavaScript packages that work in both CommonJS and ESM environments is complicated: - Dual Package Hazard: Risk of loading the same module twice in different formats - Extension Hell: Managing .js, .cjs, .mjs extensions correctly - Import Rewriting: Adjusting import paths for each module system - Package.json Exports: Complex configuration for dual module support
inop handles all of this automatically - just write TypeScript, get both formats.
Installation
``bash npm install --save-dev inop
or
pnpm add -D inop
or
yarn add -D inop `
Quick Start
Transform your TypeScript source to dual modules: `bash npx inop src build `
This creates both ESM (.js) and CommonJS (.cjs) versions of your code with proper source maps.
Example
Given this source structure: ` src/ ├── index.ts ├── utils.ts └── constants.ts `
- -p, --package - Update package.json with dual module configuration - -c, --copy - Copy package.json to build directory with optimized dependencies - -i, --ignore [patterns...] - Ignore file patterns (e.g., __tests__, *.spec.ts) - -t, --type - Source file type: js or ts (default: ts) - -m, --match - Override file matching pattern (default: */.ts) - -s, --swcrc - Custom .swcrc config path (default: .swcrc) - --commonjs-ext - CommonJS file extension (default: .cjs) - --esm-ext - ESM file extension (default: .js) - --skip-commonjs - Generate only ESM output - --skip-esm - Generate only CommonJS output - -V, --version - Show version number - -h, --help - Show help
Troubleshooting
$3
Ensure your TypeScript uses .js extensions in imports: `typescript // ✅ Correct - will be transformed appropriately import { utils } from './utils.js';