{"id":15432,"library":"father","title":"Father (NPM Package Build Tool)","description":"Father is a comprehensive NPM package development tool within the UmiJS ecosystem, designed to streamline the building, generating, and publishing of JavaScript and TypeScript packages. It features a dual-mode build system: 'Bundless' for ESModule and CommonJS outputs, leveraging esbuild, Babel, or SWC; and 'Bundle' for UMD artifacts powered by Webpack. The package, currently at version 4.6.18, maintains an active release cadence with frequent minor updates and patches. Its key differentiators include robust type generation for TypeScript, persistent caching for accelerated builds, and integrated project health checks to prevent common development pitfalls. Father also offers micro-generators for common engineering tasks and experimental dependency pre-bundling to enhance stability in Node.js frameworks and libraries.","status":"active","version":"4.6.18","language":"javascript","source_language":"en","source_url":"https://github.com/umijs/father","tags":["javascript","typescript"],"install":[{"cmd":"npm install father","lang":"bash","label":"npm"},{"cmd":"yarn add father","lang":"bash","label":"yarn"},{"cmd":"pnpm add father","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily used in `father.config.ts` for type-safe configuration. CommonJS `require` is not supported for this utility.","wrong":"const { defineConfig } = require('father');","symbol":"defineConfig","correct":"import { defineConfig } from 'father';"},{"note":"A TypeScript interface for the main Father configuration object, used for advanced type-checking or custom config structures. Always use `import type`.","wrong":"import { IFatherConfig } from 'father';","symbol":"IFatherConfig","correct":"import type { IFatherConfig } from 'father';"},{"note":"A TypeScript interface for configuration specific to the Bundless build mode. Useful for detailed type-checking in complex scenarios. Always use `import type`.","wrong":"import { IBundlessConfig } from 'father';","symbol":"IBundlessConfig","correct":"import type { IBundlessConfig } from 'father';"}],"quickstart":{"code":"{\n  \"name\": \"my-package\",\n  \"version\": \"1.0.0\",\n  \"type\": \"module\",\n  \"scripts\": {\n    \"build\": \"father build\"\n  },\n  \"devDependencies\": {\n    \"father\": \"^4.6.18\",\n    \"typescript\": \"^5.0.0\"\n  }\n}\n// father.config.ts\nimport { defineConfig } from 'father';\n\nexport default defineConfig({\n  esm: { type: 'babel', importLibToEs: true },\n  cjs: { type: 'babel', lazy: true },\n  // Optional: UMD build for browser compatibility\n  // umd: { name: 'myPackage', output: 'dist' },\n  // Persistent caching for faster rebuilds\n  extraBabelPlugins: [\n    ['babel-plugin-import', { libraryName: 'lodash', libraryDirectory: 'es' }]\n  ],\n  targets: { esmodules: true, node: 14 }\n});\n// src/index.ts\nexport const greet = (name: string): string => `Hello, ${name} from Father!`;\n\nexport const add = (a: number, b: number): number => a + b;\n","lang":"typescript","description":"Demonstrates setting up a basic TypeScript package with Father, including configuration for ESModule and CommonJS outputs, and a build script."},"warnings":[{"fix":"Refer to the official 'upgrading.md' guide (linked in the README) for detailed migration steps, focusing on configuration file changes and new build options.","message":"Upgrading from Father 2.x to Father 4.x introduces significant breaking changes due to a complete rewrite and architectural shifts. Direct upgrade often requires reconfiguring build processes.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Carefully review the `esm`, `cjs`, and `umd` configuration options in `father.config.ts`. Ensure `type` and `platform` settings match your target environment and module format requirements.","message":"Incorrectly configuring Bundless vs. Bundle modes, or choosing the wrong build core (esbuild, Babel, SWC for Bundless; Webpack for Bundle) can lead to unexpected output formats or compatibility issues.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"If encountering unexpected build results, try clearing the Father cache by deleting the `.father` directory in your project root, or running `father build --clean` if available (check CLI options).","message":"While persistent caching is a feature, in rare cases it might lead to stale build artifacts if the cache is not properly invalidated after certain changes (e.g., changes to external dependencies not tracked by Father).","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run `npm install father` or `pnpm install father` or `yarn add father` in your project's root directory. Ensure it's listed in `devDependencies`.","cause":"The `father` package is not installed in the project or is not accessible in the current execution environment.","error":"Error: Cannot find module 'father'"},{"fix":"Review your `father.config.ts` against the official documentation and the type definitions (`IFatherConfig`, `IBundlessConfig`, etc.) for any incorrect or missing properties. Your IDE should provide type hints.","cause":"The configuration object passed to `defineConfig` in `father.config.ts` does not conform to the `IFatherConfig` type definition.","error":"TypeScript error: Argument of type '{ ... }' is not assignable to parameter of type 'IFatherConfig'."},{"fix":"Either remove the `output` property from the `esm` or `cjs` configuration block, or disable `auto` if you intend to specify custom output paths manually.","cause":"Conflicting configuration where an explicit output path is provided for ESModule or CommonJS builds while the `auto` output directory generation is also active.","error":"Build failed: 'output' cannot be set for 'esm' or 'cjs' when 'auto' is enabled."}],"ecosystem":"npm"}