Skip to content

How to Fix macOS PKG Build Errors — Installer Package Creation

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about How to Fix macOS PKG Build Errors. We cover key concepts, practical examples, and best practices.

The Problem

Building an installer package fails:

productbuild: error: No component files specified.

or:

pkgbuild: error: Could not create package.

Quick Fix

Step 1: Build a component package

WRONG — missing component:

pkgbuild --root /tmp/MyApp.app --identifier com.example.app MyApp.pkg

RIGHT:

pkgbuild --root /path/to/MyApp.app   --install-location /Applications   --identifier com.example.app   --version 1.0   --scripts scripts/   MyAppComponent.pkg

Step 2: Build a distribution package from components

productbuild --package MyAppComponent.pkg   --distribution distribution.plist   MyAppInstaller.pkg

Step 3: Create distribution.plist

<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion="2">
    <title>MyApp Installer</title>
    <options customize="never" allow-external-scripts="no"/>
    <domains enable_anywhere="true"/>
    <pkg-ref id="com.example.app"/>
    <choices-outline>
        <line choice="default"/>
    </choices-outline>
    <choice id="default" visible="false">
        <pkg-ref id="com.example.app"/>
    </choice>
    <pkg-ref id="com.example.app" onConclusion="none">MyAppComponent.pkg</pkg-ref>
</installer-gui-script>

Step 4: Sign the installer

productsign --sign "Developer ID Installer: Name (TEAMID)" MyAppInstaller.pkg MyAppSigned.pkg

Step 5: Verify the package

pkgutil --check-signature MyAppInstaller.pkg

Step 6: Flat package from app bundle

pkgbuild --component /path/to/MyApp.app   --install-location /Applications   --sign "Developer ID Installer: Name (TEAMID)"   MyApp.pkg

Prevention

  • Always specify --install-location for component packages.
  • Use productsign for signing distribution packages.
  • Test the installer with installer -pkg MyApp.pkg -target /.

Common Mistakes with pkg build error

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world MACOS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between pkgbuild and productbuild?

pkgbuild creates component packages (.pkg) from files. productbuild creates distribution packages that wrap multiple component packages with a GUI installer.

How do I make an uninstallable package?

Create a preinstall/postinstall script in the --scripts directory, or use a launchd plist to register an uninstaller.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro