Summer Sale! All accounts are 50% off this week.

rseletsk's avatar

CLI app: build results in runtime error

CLI app:build results in 'Failed to compile the application'

Output: Failed to compile the application.

at vendor/laravel-zero/framework/src/Commands/BuildCommand.php:171

When debug via ./vendor/laravel-zero/framework/bin/box compile --config box.json --debug [debug] Changed the memory limit from "128MB" to "512M" [debug] Checking BOX_ALLOW_XDEBUG [debug] phar.readonly is disabled [debug] The Xdebug extension is loaded (3.5.3) xdebug.mode=develop [debug] Process restarting (BOX_ALLOW_XDEBUG=internal|3.5.3|1||) [debug] Running: [/opt/remi/php84/root/usr/bin/php, ./vendor/laravel-zero/framework/bin/box, compile, --config, box.json, --debug] [debug] Current memory limit: "512MB" [debug] Checking BOX_ALLOW_XDEBUG [debug] Restarted (90 ms). The Xdebug extension is not loaded

____

/ __ )____ _ __ / __ / __ | |// / // / // /> < /__/_//|_|

Box version 4.7.0@9c2a430 2026-03-18 09:37:27 UTC

// Loading the configuration file "box.json".

πŸ”¨ Building the PHAR "/home/rsatpriv/canvassettings/canvassettings.phar"

[debug] Increased the maximum number of open file descriptors from ("1024", "262144") to ("2176", "unlimited") ? Checking Composer compatibility > '/usr/local/bin/composer' '--version' '--no-ansi' > Version detected: 2.8.9 (Box requires ^2.2.0) > Supported version detected ? Registering compactors

  • KevinGH\Box\Compactor\Php
  • KevinGH\Box\Compactor\Json ? Adding main file: /home/rsatpriv/canvassettings/canvassettings ? Adding requirements checker ? Adding binary files

    No file found ? Auto-discover files? No ? Exclude dev files? Yes ? Adding files 8182 file(s) ? Generating new stub

  • Using shebang line: #!/usr/bin/env php
  • Using banner:

    Generated by Humbug Box 4.7.0@9c2a430.

    @link https://github.com/humbug/box ? Dumping the Composer autoloader [debug] Restored the maximum number of open file descriptors

In Box.php line 81:

[ErrorException] chdir(): No such file or directory (errno 2)

0 likes
1 reply
LaryAI's avatar
Level 58

Based on the error message you’ve posted:

[ErrorException]
chdir(): No such file or directory (errno 2)

during the PHAR build process with Laravel Zero (via Box), this typically means that Box is trying to change to a directory that no longer exists or is incorrect in your config or project setup.

Here’s how to troubleshoot and resolve it:


1. Check for a valid working directory in your box.json

If your box.json uses a cwd (current working directory) or any directories settings, make sure all paths are correct and exist. It’s common for directory structure to change, or typos to sneak in.

Example from a box.json:

{
    "directories": ["app", "bootstrap", "config", "vendor"],
    ...
}

If those folders are missing or misnamed in your project root, Box could fail.


2. Verify your composer.json "bin" setting

If you set a custom bin path in composer.json, ensure that file exists, is executable, and points to a valid script.

Example:

{
    "bin": [
        "canvassettings"
    ]
}

Does canvassettings exist in your project root? Is it executable (chmod +x canvassettings)?


3. Missing or Misplaced Files

From your build log:

? Adding binary files
No file found

This hints that your main binary file is missing or not where Box expects it.

  • Make sure the "main" file defined in box.json (or the default, project root with same name as project) exists and is executable.

Example box.json setting:

{
    "main": "canvassettings"
}

You should have a file at:

/home/rsatpriv/canvassettings/canvassettings

If not, create one or update the path in box.json.


4. Auto-discovery Confirmation Problem

From your log:

? Auto-discover files? No

If you answered "No" and misconfigured file inclusion, Box might not be able to gather the correct files, leading to issues. Consider answering "Yes", or manually curate your included files in box.json.


5. Running from Proper Project Root

Box (and Laravel Zero) expects you to run the build from your project root folder. If you run the build command from a different directory, relative paths can break!

Always run:

php ./vendor/bin/laravel-zero app:build

from the root of your project.


6. General Recommended Solution to Your Error

Double check:

  • Your main binary path (as set in box.json) exists and is executable.
  • All paths in box.json (directories, main, etc.) are valid.
  • You’re running commands from the root project directory.
  • Your working directory exists and is accessible.

Example: Project Structure

Your project directory should look something like:

canvassettings/
β”œβ”€β”€ app/
β”œβ”€β”€ bootstrap/
β”œβ”€β”€ config/
β”œβ”€β”€ vendor/
β”œβ”€β”€ canvassettings           <-- this file should exist and be executable
β”œβ”€β”€ composer.json
β”œβ”€β”€ box.json

Sample box.json

Adjust to fit your setup:

{
    "main": "canvassettings",
    "output": "canvassettings.phar",
    "directories": [
        "app",
        "bootstrap",
        "config",
        "vendor"
    ],
    "files": [
        "composer.json",
        "artisan" // if you have a custom binary, reference it here
    ]
}

Make sure the main file exists.


Final Checklist

  1. main script exists and is executable:
    ls -l canvassettings
    # if missing or not executable:
    touch canvassettings
    chmod +x canvassettings
    
  2. Run build from project root.
  3. Check your box.json paths.
  4. Re-run your build:
    php ./vendor/bin/laravel-zero app:build
    
    or (if debugging)
    ./vendor/laravel-zero/framework/bin/box compile --config box.json --debug
    

Summary

The error is almost always due to a missing or misconfigured binary (main) file, or invalid working directory specified in box.json. Double check the paths, ensure all referenced files exist, and run the build from the correct directory.

If you continue having trouble, please paste:

  • The contents of your box.json
  • Your directory tree (output of tree -L 2 .)
  • The full command you are running

for more specific diagnostics.

Please or to participate in this conversation.