{"id":15649,"library":"imod","title":"iMod Bundler","description":"iMod is a command-line interface (CLI) and programmatic JavaScript API-based bundler specifically designed for creating small, efficient modules. It is powered by Rollup, abstracting much of its complexity to provide a streamlined experience. Currently at version 1.5.0, iMod offers integrated TypeScript type declaration generation and simplifies the setup for common module formats including ES Modules (ESM), CommonJS (CJS), and UMD. While a specific release cadence isn't detailed, it generally follows semantic versioning. Its key differentiators include an opinionated yet configurable build pipeline, a focus on ease of use for 'tiny modules,' and support for multiple configuration methods via `package.json` or dedicated configuration files like `imod.config.js`.","status":"active","version":"1.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/haozi/iMod","tags":["javascript","rollup","tiny module","typescript"],"install":[{"cmd":"npm install imod","lang":"bash","label":"npm"},{"cmd":"yarn add imod","lang":"bash","label":"yarn"},{"cmd":"pnpm add imod","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"iMod is 'powered by Rollup' and uses it as its core bundling engine.","package":"rollup","optional":false}],"imports":[{"note":"Primary way to import the main class for programmatic usage in ESM contexts. While a CommonJS require might work in older Node.js, the project is TypeScript-first.","wrong":"const Imod = require('imod')","symbol":"Imod","correct":"import Imod from 'imod'"},{"note":"Correct CommonJS import for use in Node.js environments that do not support ES modules natively, or in scripts that explicitly use require. Using `import` here would result in a syntax error.","wrong":"import Imod from 'imod'","symbol":"Imod","correct":"const Imod = require('imod')"},{"note":"Import for TypeScript type definitions, useful when defining custom iMod configurations in a `.ts` file.","symbol":"ImodConfig","correct":"import type { ImodConfig } from 'imod'"}],"quickstart":{"code":"import Imod from 'imod';\nimport path from 'path';\n\n// Initialize iMod with the current working directory as the project root.\n// Adjust 'cwd' if your project root is different from where this script runs.\nconst iModInstance = new Imod({\n  cwd: path.resolve(__dirname, '..', '..') // Assumes script is in 'scripts/build.ts' and project root is two levels up\n});\n\nconsole.log('Starting iMod build process...');\n\niModInstance.build()\n  .then(() => {\n    console.log('iMod build completed successfully!');\n    console.log('Check the ' + (iModInstance.config.outDir || './dist') + ' directory for compiled output.');\n  })\n  .catch((error: any) => {\n    console.error('iMod build failed:', error);\n    process.exit(1);\n  });\n\n// To run in development/watch mode:\n// iModInstance.dev().then(() => {\n//   console.log('iMod is now watching for changes...');\n// });","lang":"typescript","description":"Demonstrates programmatic initialization of iMod and execution of a build operation, logging success or failure."},"warnings":[{"fix":"Use `imod init ./my-project --lite=true` to skip the automatic installation of `node_modules` during project creation.","message":"When initializing a new project, running `imod init` without the `--lite` flag will automatically attempt to install `node_modules`. This can be unexpected and time-consuming for users who prefer manual dependency management.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"To avoid unexpected configuration overrides, consolidate your iMod configuration into a single, high-priority file (e.g., `./imod.config.js`) or explicitly manage your configuration across files.","message":"iMod resolves its configuration files in a specific order: `./imod.config.js` > `./imod.config.json` > `imodconfig.js` > `imodconfig.json` > `${package.json}.config.imod`. Be aware that configurations found earlier in this sequence will override those found later.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Modify your iMod configuration (e.g., in `imod.config.js`) to set `target: 'esnext'` or a specific modern ES version within the `compilerOptions` array for the CJS format, if you are targeting modern Node.js environments.","message":"By default, iMod's `compilerOptions` for the CommonJS (CJS) format targets `es5`, which may not be optimal for modern Node.js environments that support newer ECMAScript features.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure an entry file (e.g., `src/index.ts`) exists at the default location, or specify a custom input file in your iMod configuration (e.g., add `input: 'path/to/my-entry.js'` to `imod.config.js`).","cause":"iMod could not find an entry file that matches its default search patterns (`src/index.*`) in the project's 'src/' directory.","error":"Error: Could not resolve entry module (./src/index.{ts,tsx,js,jsx,es6,es,mjs})"},{"fix":"Install the package by running `npm install imod` or `yarn add imod`. If using TypeScript, ensure `allowSyntheticDefaultImports` is enabled in your `tsconfig.json` if you are using `import Imod from 'imod'`.","cause":"The 'imod' package is not installed in the project, or the TypeScript compiler cannot locate its type definitions.","error":"Cannot find module 'imod' or its corresponding type declarations."},{"fix":"Review your source code to eliminate CommonJS-specific `require()` calls and `module.exports` when targeting ESM output. If you must use CommonJS modules, ensure iMod is configured to transpile them correctly (e.g., via a Rollup CJS plugin if exposed by iMod) or generate a CommonJS output format for that specific bundle.","cause":"This error typically occurs when an ES Module (ESM) bundle generated by iMod attempts to execute CommonJS `require()` syntax in an environment that expects pure ESM.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}