Moatasem
Trouble Autoloading Classes in Railway: Running composer dump-autoload for 'Utilities' Namespace
I've created a "utilities" folder in my Laravel project, and inside it, there's a file named "Variables.php" with the following content:
namespace Utilities;
class Variables
{
public static $HELLO_WORLD = 'Hello World';
}
Locally, everything works fine after running the composer dump-autoload command. However, when I deploy the project to Railway, it seems to have trouble detecting the "Variables" file when I use it, resulting in build failures.
I'm wondering where and how I should run the composer dump-autoload command in the Railway environment to ensure that the "Utilities" namespace and the "Variables" class are properly recognized.
I'd appreciate any guidance or assistance in resolving this issue. My project ID is 023df63f-2cfb-4b24-8255-8b29f98e2033 (private project).
Thank you in advance for your help!3 replies
Laravel: failed to build project
Hello, I am new to Railway. I am trying to deploy laravel project from my github repo, which is a regular laravel project without using railway templates. I stumbled through this issue at ed49629d-de29-4a0d-9c17-b6d525c141d6. I tried creating railway.json file and deploy it with the following content and it did not succeed.
Problem is that I created a php file and I am using it in multiple files and to do that I used to run composer dump-autoload locally, but here it seems I cannot do it
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS",
"buildCommand": "version: 2 commands: build: steps: - name: install command: yarn install - name: build command: yarn build start: command: php artisan serve --host 0.0.0.0 --port $PORT dump-autoload: composer dump-autoload"
},
"deploy": {
"numReplicas": 1,
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
ERROR MESSAGE:
Generating optimized autoload files
#12 9.834 > Illuminate\Foundation\ComposerScripts::postAutoloadDump
#12 9.861 > @php artisan package:discover --ansi
#12 10.04 Error
#12 10.17 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
#12 ERROR: process "/bin/bash -ol pipefail -c composer install --ignore-platform-reqs" did not complete successfully: exit code: 1
2 replies