Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while trying to build phar file #492

Open
alfhh opened this issue Jun 4, 2024 · 8 comments
Open

Error while trying to build phar file #492

alfhh opened this issue Jun 4, 2024 · 8 comments

Comments

@alfhh
Copy link

alfhh commented Jun 4, 2024

Hello!!

I'm currently facing an issue while trying to build the a phar.

This is the error that I'm getting:

  The command "'./box' 'compile' '--working-dir=/Users/ahinojosa/workspace/movie-cli' '--config=/Users/ahinojosa/workspace/movie-cli/box.json'" failed.

Working directory: /Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin

Error: proc_open(): posix_spawn() failed: No such file or directory

I faced this issue with an existing project but I also face this problem if I start a brand new project following the installation instructions.

Things that I have tried:

  • My box.json file exists and is present on the project
  • Moved all dependencies (except php) to require-dev

My guess is that I'm missing something in the setup piece, but I followed the available documentation, if there is a gap in the installation guide I'm happy to raise a PR once I get this to work.

Any guidance?
Thanks!!1

image
@owenvoke
Copy link
Member

owenvoke commented Jun 4, 2024

Just to check if it's a Box issue, does it build if you run:

vendor/laravel-zero/framework/bin/box compile --config box.json

You should end up with a file called movie-cli.phar in the root directory.

Can also add a --debug option if it doesn't work, to get some further information.

Also, could you provide some information on your setup? Which OS and PHP version are you using?

@alfhh
Copy link
Author

alfhh commented Jun 4, 2024

Thanks for the reply @owenvoke.

Still failing and phar file is not created, but I got a different error message:

Box version 4.6.2@29c3585 2024-04-23 19:35:41 UTC

 // Loading the configuration file "box.json".
 [ERROR] The configuration file is invalid.


In Assert.php line 1012:

  [_HumbugBoxc5dcacdc09f0\Webmozart\Assert\InvalidArgumentException]
  The file "/Users/ahinojosa/workspace/movie-cli/builds/movie-cli" does not exist.

Is weird to see this error since my box.json file is present.

Project structure:

image

Error:

image

Full Stacktrace:

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 enabled
[debug] The Xdebug extension is not loaded
[debug] Configured `phar.readonly=0`
[debug] Process restarting (BOX_ALLOW_XDEBUG=internal||1|*|*)
[debug] Running: [/usr/local/Cellar/php/8.3.7/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 (127 ms). The Xdebug extension is not loaded

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


Box version 4.6.2@29c3585 2024-04-23 19:35:41 UTC

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


 [ERROR] The configuration file is invalid.



In Assert.php line 1012:

  [_HumbugBoxc5dcacdc09f0\Webmozart\Assert\InvalidArgumentException]
  The file "/Users/ahinojosa/workspace/movie-cli/builds/movie-cli" does not exist.


Exception trace:
  at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/webmozart/assert/src/Assert.php:1012
 _HumbugBoxc5dcacdc09f0\Webmozart\Assert\Assert::reportInvalidArgument() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/webmozart/assert/src/Assert.php:691
 _HumbugBoxc5dcacdc09f0\Webmozart\Assert\Assert::fileExists() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/webmozart/assert/src/Assert.php:696
 _HumbugBoxc5dcacdc09f0\Webmozart\Assert\Assert::file() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/src/Configuration/Configuration.php:786
 _HumbugBoxc5dcacdc09f0\KevinGH\Box\Configuration\Configuration::retrieveMainScriptPath() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/src/Configuration/Configuration.php:147
 _HumbugBoxc5dcacdc09f0\KevinGH\Box\Configuration\Configuration::create() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/src/Configuration/ConfigurationLoader.php:21
 _HumbugBoxc5dcacdc09f0\KevinGH\Box\Configuration\ConfigurationLoader->loadFile() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/src/Console/ConfigurationLoader.php:22
 _HumbugBoxc5dcacdc09f0\KevinGH\Box\Console\ConfigurationLoader::getConfig() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/src/Console/Command/ConfigOption.php:22
 _HumbugBoxc5dcacdc09f0\KevinGH\Box\Console\Command\ConfigOption::getConfig() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/src/Console/Command/CompileCommand.php:115
 _HumbugBoxc5dcacdc09f0\KevinGH\Box\Console\Command\CompileCommand->execute() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/fidry/console/src/Bridge/Command/SymfonyCommand.php:69
 _HumbugBoxc5dcacdc09f0\Fidry\Console\Bridge\Command\SymfonyCommand->execute() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/symfony/console/Command/Command.php:151
 _HumbugBoxc5dcacdc09f0\Symfony\Component\Console\Command\Command->run() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/symfony/console/Application.php:690
 _HumbugBoxc5dcacdc09f0\Symfony\Component\Console\Application->doRunCommand() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/symfony/console/Application.php:230
 _HumbugBoxc5dcacdc09f0\Symfony\Component\Console\Application->doRun() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/symfony/console/Application.php:123
 _HumbugBoxc5dcacdc09f0\Symfony\Component\Console\Application->run() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/vendor/fidry/console/src/Application/ApplicationRunner.php:39
 _HumbugBoxc5dcacdc09f0\Fidry\Console\Application\ApplicationRunner->run() at phar:///Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box/bin/box:47
 require() at /Users/ahinojosa/workspace/movie-cli/vendor/laravel-zero/framework/bin/box:19

@natanaelsinisalo
Copy link

I'm having exactly the same issue with:

laravel-zero/foundation v11.5.0
laravel-zero/framework v11.0.1
PHP 8.3.7

@owenvoke
Copy link
Member

Sorry, I completely forgot to get back to this. I was able to replicate it locally.

Unfortunately, I don't have time at the moment to investigate it further though. I'm pretty sure it's something to do with the current working directory that Box runs in (possibly due to the binary being re-run).

@natanaelsinisalo
Copy link

natanaelsinisalo commented Jun 10, 2024

No worries. I downgraded my project back to laravel-zero 10 and build seems to work now fine. I might try to debug and create a PR to resolve this issue next weekend if someone else haven't had time to fix it before that 🙃

@SamuelMwangiW
Copy link

SamuelMwangiW commented Jun 10, 2024

I also ran into the same issue. Running vendor/laravel-zero/framework/bin/box compile --config box.json works successfully. I figured therefore it maybe the box command is being run from the wrong path.

As a temporary workaround, I created a symlink in the CWD with which worked for me

ln vendor/laravel-zero/framework/bin/box box

@mho22
Copy link

mho22 commented Jun 14, 2024

@owenvoke the issue occurs in BuildCommand file in compile method on line 152.

laravel-zero/framework/src/Commands/BuildCommand.php on line 152

foreach (tap($process)->start() as $type => $data) {
...

In fact, the $process returns and exception because it can't find the ./box path.

I dug deeper and found out that the Process->start method in file Process.php uses @proc_open and this one, even if it uses the $this->cwd attribute, doesn't find the ./box path.

symfony/process/Process.php on line 363 :

$process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);

$process is false .

It works if you add this line before @proc_open :

$commandline[0] = "$this->cwd/$commandline[0]";

$process = @proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);

So it seems that @proc_open doesn't take $this->cwd into account. I don't know why.

And this is probably linked with PHP8.3 and this link could possibly be the reason.

@alfhh
Copy link
Author

alfhh commented Jun 24, 2024

Thanks for all the comments on this thread!

I was able to unblock my build by using this workaround, thank you @SamuelMwangiW

I also ran into the same issue. Running vendor/laravel-zero/framework/bin/box compile --config box.json works successfully. I figured therefore it maybe the box command is being run from the wrong path.

As a temporary workaround, I created a symlink in the CWD with which worked for me

ln vendor/laravel-zero/framework/bin/box box

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants