I pushed some changes to our repo and they auto-deployed to Forge. The deployment failed with this error:
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'MyRepo\MyPackage\MyServiceProvider' not found
Script php artisan optimize handling the post-install-cmd event returned with error code 1
So I edited the config/app.php file to temporarily comment out that service provider line, then re-ran composer update without any problems to artisan optimize this time.
I then uncommented the service provider line and ran artisan optimize again to make sure all was well and got no errors.
Because the composer.lock file changed on Forge after this composer update, I pushed it to the repo.
This triggered yet another artisan optimize error for that same service provider. So I repeated my steps above.
Now every single time there is a new deploy from the repo, artisan optimize triggers that error on that service provider even if we didn't add new service providers.
If I simply run composer update then I'm right back with the same artisan optimize error as before.
Tried doing composer clear-cache but that didn't fix it.
I ran a test script to make sure that service provider is working and autoloaded as expected by calling the class it loads, so I've verified the PSR-4 namespace works just fine.
Here is my project composer.json:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"laravel/framework": "5.2.*",
"laravel/cashier": "~6.0",
"my-repo/my-package": "dev-master"
},
"require-dev": {
"fzaninotto/faker": "~1.6",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5",
"phpunit/phpunit-mock-objects": "3.2.*#dev"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
},
"repositories": [
{
"type": "git",
"url": "git#bitbucket.org:my-repo/my-package.git"
}
]
}
Here is our private package's composer.json:
{
"name": "my-repo/my-package",
"description": "My package.",
"type": "package",
"require": {
"php": ">=5.5.9",
"illuminate/support": "5.2.*"
},
"require-dev": {
"raveren/kint": "~1"
},
"autoload": {
"psr-4": {
"MyRepo\\MyPackage\\": "src/"
},
"files": [
"src/MyPackage/helpers.php"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
Even if I change the project's composer.json to pull this by {"type": "path", "url": "./library/my-repo"} I get the same error.
It's as if the optimized class loader is cleared of private repo classes every time I run composer update.
I'm pretty stuck here.
Related
I am trying to modify an existing composer package.
I forked the original package from github, cloned it on my local machine and now trying to make my laravel app use it with the following composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": "5.6.*",
....
"vendor/packagenamehere": "dev-dynamic-logo",
....
},
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
"url": "https://www.setasign.com/downloads/"
},
{
"type": "path",
"url": "path/to/package/on/my/machine",
"options": {
"symlink": true
}
}
],
"require-dev": {
"fzaninotto/faker": "~1.4",
"laravel/dusk": "^1.0",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7",
"staudenmeir/dusk-updater": "^1.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Helpers/env.php",
....
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
Then im firing composer update vendor/packagename --prefer-dist - and nothing.
No matter what I try, composer still grabs from packagist.
Any ideas?
From https://getcomposer.org/doc/05-repositories.md#path :
If the package is a local VCS repository, the version may be inferred by the branch or tag that is currently checked out. Otherwise, the version should be explicitly defined in the package's composer.json file. If the version cannot be resolved by these means, it is assumed to be dev-master.
Make sure that the "dynamic-logo" branch is checked out in your cloned package repo or update the version in the composer.json of the package.
Also check that the name of the package declared in it's composer.json matches your "vendor/packagename".
I am using Laravel version 5.2 and Jenssegers MongoDB. I installed both and working fine but I have to use any other library and made changes in composer.json after that use command composer update. After using this command automatically Jenssegers MongoDB file removed. I don't know why this happen. After composer update why Jenssegers MongoDB file removed automatically? Please suggest me how to handel this?
My composer.json file
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"acacha/admin-lte-template-laravel": "2.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"app/common_helper.php"
]
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
Write this "jenssegers/mongodb": "*", line in your composer.json file:-
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"acacha/admin-lte-template-laravel": "2.*",
"jenssegers/mongodb": "*",
},
And add the service provider in config/app.php
Jenssegers\Mongodb\MongodbServiceProvider::class,
Jenssegers\Mongodb\Auth\PasswordResetServiceProvider,
then go to project root directory in terminal and run command composer update .
In model file, you need to add below line at the top,
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
Reference :- documentation
composer update --no-scripts
you can stop scripts run
I am using Laravel 5.1 and trying to install a new package via composer. I am using following command.
composer require "matriphe/imageupload:5.1.*"
I am getting following error.
./composer.json has been updated
> php artisan clear-compiled
Package "matriphe/imageupload" listed for update is not installed. Ignoring.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
> php artisan optimize
Generating optimized class loader
I also tried running
composer self-update
This is the message I received.
You are already using composer version f1aa655e6113e0efa979b8b09d7951a762eaa04c.
I have also tried updating composer dependencies for project via manually adding package name to composer.json and running.
composer update
and
partially updating via.
composer update "matriphe/imageupload:5.1.*"
Up until now I have installed other packages and all of them were installed except this one.
For me, it was simply a typo in the package name.
Update: I solved the issue in the most bizzare way possible.
I initially had following composer.json file when I ran the command
composer require "matriphe/imageupload:5.1.*"
and
composer require laravelcollective/html:~5.0
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"matriphe/imageupload": "5.1.*",
"laravelcollective/html": "~5.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
And got the error.
Package "matriphe/imageupload" listed for update is not installed. Ignoring.
and
Package "laravelcollective/html" listed for update is not installed. Ignoring
To solve it I manually added another require array in json added packages to be installed which is given below.
"require": {
"laravelcollective/html": "~5.0",
"matriphe/imageupload": "5.1.*"
}
My modified composer.json file look like this.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*"
},
"require": {
"laravelcollective/html": "~5.0",
"matriphe/imageupload": "5.1.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"pre-update-cmd": [
"php artisan clear-compiled"
],
"post-update-cmd": [
"php artisan optimize"
],
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
and ran the following command.
composer update
It did the trick for me.
I created a brand new Laravel 5 application via laravel new mysite. When I open the site I see the following errors:
Notice: date_default_timezone_set(): Timezone ID '' is invalid in /mysite/storage/framework/compiled.php on line 1790
Fatal error: Call to undefined method Illuminate\Foundation\Bootstrap\ConfigureLogging::configureHandler() in /mysite/storage/framework/compiled.php on line 1656
Here is my composer.json:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
I've already ran composer update to make sure I have the latest dependencies, but I'm still getting the same error. Any ideas?
Edit: I'm using PHP 5.4
Edit 2: It works when running via php artisan serve but not when using my my dev box running apache to serve the site. So it could be a local php issue on that box.
I believe this issue has to do with your local server settings. I had the same issue on my local server and I set the value date.timezone in my php.ini
I have a satis private repo set up on the url http://packages.ex/, which, when I visit it, lists two packages: example/admin and example/codebase
When I run composer create-project example/codebase new-site --repository-url=http://packages.ex stability=dev I get the error:
[InvalidArgumentException]
Could not find package example/codebase with version stability=dev.
The composer.json inside example/codebase looks like this:
{
"name": "example/codebase",
"description": "Example codebase.",
"keywords": ["codebase", "example"],
"homepage": "http://www.exampple.com",
"version": "0.1",
"repositories": [ { "type": "composer", "url": "http://packages.ex/" } ],
"authors": [
{
"name": "Example",
"email": "example#example.com"
}
],
"require": {
"php": ">=5.4.0",
"ext-mcrypt": "*",
"laravel/framework": "4.1.*",
"way/generators": "dev-master",
"example/admin": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"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"
}
I don't know why composer can't find the package as when I visit the private repo in a browser it's there, and I'm specifying 'minimum-stability': 'dev' in composer.json.
Maybe I'm missing something or doing something wrong. Any ideas?
Is there any way to run a command line check to see if composer can access a particular package and what stabilities it has?
Looks like you have an error or typo in your repository-url parameter and composer try to find package on default packagist.org repo.