Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

fenos's avatar

Autoload Composer error after L5 Installation

I created a fresh installation of laravel 5 and it come out with this kind of error:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'A non-empty PSR-4 prefix must end with a namespace separator.' in /home/vagrant/laravel/vendor/composer/ClassLoader.php on line 219

InvalidArgumentException: A non-empty PSR-4 prefix must end with a namespace separator. in /home/vagrant/laravel/vendor/composer/ClassLoader.php on line 219

This kind of error come out when the composer.json under autoload section is not formatted on right way but it seem correctly any suggest?

0 likes
20 replies
xingfucoder's avatar

@Fenos, could you show here the content of your composer.json file?

Did you run the php artisan app:name command?

fenos's avatar

Yes I run app::name command even if I think it's not a required step. This is my composer.json


{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "laravel/framework": "~5.0", "laravel/elixir": "~1.0" }, "require-dev": { "phpunit/phpunit": "~4.0" }, "autoload": { "classmap": [ "database", "tests/TestCase.php" ], "psr-4": { "Test\\": "app/" } }, "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan route:scan", "php artisan event:scan", "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-create-project-cmd": [ "php artisan key:generate" ] }, "config": { "preferred-install": "dist" }, "minimum-stability": "dev" }

It looks correct to me. After that I even run composer dump-autoload -o

jrean's avatar

If it's a fresh project, don't waste time.

rm -rf your-project directory

then

composer create-project laravel/laravel test-laravel-5-project dev-develop --prefer-dist

then

php artisan app:name name
xingfucoder's avatar

@fenos, If you change your psr-4 in composer.json your application may crash. I recommend to change using app:name command.

@jrean how did you use this command? Is used all together?

UPDATE. Now I can see your code formatted.

fenos's avatar

I deleted and removed the project 3 times but same thing. But this is not the first time I install L5 and is never happened

jrean's avatar

Just trying a fresh install from composer right now. W8 and I will see if I have the error :)

fenos's avatar

Thanks a lots, maybe I just missing something. I hope so. I did the installation in Homestead

xingfucoder's avatar

@Jrean, when I was writing my answer, your code appears all together and I was thinking you can use all command in the same line :) sorry.

jrean's avatar
jrean
Best Answer
Level 8

@fenos, I just did and everything is working. I also did a php artisan app:name Test ... Please do a

composer selfupdate

I don't create project from homestead. Doing install from my local machine within the directory shared with Homestead

1 like
xingfucoder's avatar

With laravel homestead I usually follow two ways:

  1. Unzip the Laravel Dev 5 repository within my code folder and then run composer install.
  2. Use the following command:
    composer create-project laravel/laravel mylaravelprojectname dev-develop

After this step I update my homestead.yaml and run vagrant up and vagrant provision.

These two commands clone your local project folder within your VM Homestead.

You will need to update your host file.

jrean's avatar

@fenos Are you running under Os x? To solve the problem first forget Homestead. Open terminal and choose a location (~/Desktop is fine) Then just try to

composer create-project laravel/laravel test-laravel-5-project dev-develop

then

php artisan app:name Test

No reason it will not work.

fenos's avatar

Yes i'm running on OS x, and the installation I done in my directory: ~/LaravelProjects/Laravel and I done as usual

composer create-project laravel/laravel project dev-develop

I'm just a bit tired I will figure out the problem. But why you said forget homestead in OS x?

xingfucoder's avatar

That message is shown when you run your composer create-project? Or when you run composer update after update some psr-4?

If that message is shown after run composer create-project maybe a folder permission issue?

Did you tried to create a non-dev project?

jrean's avatar

Just to "debug", I wanted you to try installing L5 directly on your local machine, not within Homestead :)

jrean's avatar

@codeatbusiness Yes you can do all commands in one. Just chain them...

rm -rf test-laravel-5-project ; composer create-project laravel/laravel test-laravel-5-project dev-develop --prefer-dist ; cd test-laravel-5-project ; php artisan app:name Test

Just adapt to your needs :)

fenos's avatar

I installed L5 with MAMP and it works, now I'm downloading the new update of laravel/homestead and see what happen. :)

xingfucoder's avatar

Hi @fenos, what is the box that you are using of Homestead?

You can see using:

vagrant box list

If you are using a box previous to the 0.2.0, I recommend to update it using:

vagrant box update

I think this error would be related with your Homestead Vagrant Box.

fenos's avatar

I solved the problem upgrading homestead and provisioning it. I just mark the correct answer to @jrean because you been kind to try out the installation

Please or to participate in this conversation.