After leaving a project for a week and returning (without changing anything) my php artisan
stopped working. This is only the case for this particular project, since php artisan
works fine in other projects. When I want to run artisan commands I am getting a
[InvalidArgumentException] Please provide valid cache path
:
PS C:\Users\Artur\PhpstormProjects\stuttard.de> php artisan serve
InvalidArgumentException
Please provide a valid cache path.
at C:\Users\Artur\PhpstormProjects\stuttard.de\vendor\laravel\framework\src\Illuminate\View\Compilers\Compiler.php:36
32▕ */
33▕ public function __construct(Filesystem $files, $cachePath)
34▕ {
35▕ if (! $cachePath) {
➜ 36▕ throw new InvalidArgumentException('Please provide a valid cache path.');
37▕ }
38▕
39▕ $this->files = $files;
40▕ $this->cachePath = $cachePath;
1 C:\Users\Artur\PhpstormProjects\stuttard.de\vendor\laravel\framework\src\Illuminate\View\ViewServiceProvider.php:88
Illuminate\View\Compilers\Compiler::__construct(Object(Illuminate\Filesystem\Filesystem))
2 C:\Users\Artur\PhpstormProjects\stuttard.de\vendor\laravel\framework\src\Illuminate\Container\Container.php:869
Illuminate\View\ViewServiceProvider::Illuminate\View\{closure}(Object(Illuminate\Foundation\Application), [])
Deleting those folders and creating them new does not help.
What can I do?
Edit:
Deleting vendor
folder and running composer install
produces the same exception
at step @php artisan package:discover --ansi
:
PS C:\Users\Artur\PhpstormProjects\stuttard.de> composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 111 installs, 0 updates, 0 removals
- Installing doctrine/inflector (2.0.3): Extracting archive
- Installing doctrine/lexer (1.2.1): Extracting archive
- Installing symfony/polyfill-ctype (v1.23.0): Extracting archive
- Installing webmozart/assert (1.10.0): Extracting archive
- Installing dragonmantank/cron-expression (v3.1.0): Extracting archive
- Installing symfony/polyfill-php80 (v1.23.1): Extracting archive
- Installing symfony/polyfill-mbstring (v1.23.1): Extracting archive
- Installing symfony/var-dumper (v5.3.8): Extracting archive
- Installing symfony/polyfill-intl-normalizer (v1.23.0): Extracting archive
- Installing symfony/polyfill-intl-grapheme (v1.23.1): Extracting archive
- Installing symfony/string (v5.3.7): Extracting archive
- Installing psr/container (1.1.1): Extracting archive
- Installing symfony/service-contracts (v2.4.0): Extracting archive
- Installing symfony/polyfill-php73 (v1.23.0): Extracting archive
- Installing symfony/deprecation-contracts (v2.4.0): Extracting archive
- Installing symfony/console (v5.3.7): Extracting archive
- Installing psr/log (2.0.0): Extracting archive
- Installing monolog/monolog (2.3.5): Extracting archive
- Installing voku/portable-ascii (1.5.6): Extracting archive
- Installing phpoption/phpoption (1.8.0): Extracting archive
- Installing graham-campbell/result-type (v1.0.2): Extracting archive
- Installing vlucas/phpdotenv (v5.3.1): Extracting archive
- Installing symfony/css-selector (v5.3.4): Extracting archive
- Installing tijsverkoyen/css-to-inline-styles (2.2.3): Extracting archive
- Installing symfony/routing (v5.3.7): Extracting archive
- Installing symfony/process (v5.3.7): Extracting archive
- Installing symfony/polyfill-php72 (v1.23.0): Extracting archive
- Installing symfony/polyfill-intl-idn (v1.23.0): Extracting archive
- Installing symfony/mime (v5.3.8): Extracting archive
- Installing symfony/http-foundation (v5.3.7): Extracting archive
- Installing symfony/http-client-contracts (v2.4.0): Extracting archive
- Installing psr/event-dispatcher (1.0.0): Extracting archive
- Installing symfony/event-dispatcher-contracts (v2.4.0): Extracting archive
- Installing symfony/event-dispatcher (v5.3.7): Extracting archive
- Installing symfony/error-handler (v5.3.7): Extracting archive
- Installing symfony/http-kernel (v5.3.9): Extracting archive
- Installing symfony/finder (v5.3.7): Extracting archive
- Installing symfony/polyfill-iconv (v1.23.0): Extracting archive
- Installing egulias/email-validator (2.1.25): Extracting archive
- Installing swiftmailer/swiftmailer (v6.2.7): Extracting archive
- Installing symfony/polyfill-php81 (v1.23.0): Extracting archive
- Installing ramsey/collection (1.2.1): Extracting archive
- Installing brick/math (0.9.3): Extracting archive
- Installing ramsey/uuid (4.2.3): Extracting archive
- Installing psr/simple-cache (1.0.1): Extracting archive
- Installing opis/closure (3.6.2): Extracting archive
- Installing symfony/translation-contracts (v2.4.0): Extracting archive
- Installing symfony/translation (v5.3.9): Extracting archive
- Installing nesbot/carbon (2.53.1): Extracting archive
- Installing league/mime-type-detection (1.8.0): Extracting archive
- Installing league/flysystem (1.1.5): Extracting archive
- Installing nette/utils (v3.2.5): Extracting archive
- Installing nette/schema (v1.2.1): Extracting archive
- Installing dflydev/dot-access-data (v3.0.1): Extracting archive
- Installing league/config (v1.1.1): Extracting archive
- Installing league/commonmark (2.0.2): Extracting archive
- Installing laravel/serializable-closure (v1.0.2): Extracting archive
- Installing laravel/framework (v8.62.0): Extracting archive
- Installing facade/ignition-contracts (1.0.2): Extracting archive
- Installing facade/flare-client-php (1.9.1): Extracting archive
- Installing facade/ignition (2.14.0): Extracting archive
- Installing fakerphp/faker (v1.16.0): Extracting archive
- Installing asm89/stack-cors (v2.0.3): Extracting archive
- Installing fruitcake/laravel-cors (v2.0.4): Extracting archive
- Installing psr/http-message (1.0.1): Extracting archive
- Installing psr/http-client (1.0.1): Extracting archive
- Installing ralouphie/getallheaders (3.0.3): Extracting archive
- Installing psr/http-factory (1.0.1): Extracting archive
- Installing guzzlehttp/psr7 (2.0.0): Extracting archive
- Installing guzzlehttp/promises (1.4.1): Extracting archive
- Installing guzzlehttp/guzzle (7.3.0): Extracting archive
- Installing laravel/sail (v1.11.0): Extracting archive
- Installing laravel/sanctum (v2.11.2): Extracting archive
- Installing nikic/php-parser (v4.13.0): Extracting archive
- Installing psy/psysh (v0.10.8): Extracting archive
- Installing laravel/tinker (v2.6.2): Extracting archive
- Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
- Installing mockery/mockery (1.4.4): Extracting archive
- Installing filp/whoops (2.14.4): Extracting archive
- Installing nunomaduro/collision (v5.10.0): Extracting archive
- Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
- Installing phpdocumentor/type-resolver (1.5.1): Extracting archive
- Installing phpdocumentor/reflection-docblock (5.2.2): Extracting archive
- Installing sebastian/version (3.0.2): Extracting archive
- Installing sebastian/type (2.3.4): Extracting archive
- Installing sebastian/resource-operations (3.0.3): Extracting archive
- Installing sebastian/recursion-context (4.0.4): Extracting archive
- Installing sebastian/object-reflector (2.0.4): Extracting archive
- Installing sebastian/object-enumerator (4.0.4): Extracting archive
- Installing sebastian/global-state (5.0.3): Extracting archive
- Installing sebastian/exporter (4.0.3): Extracting archive
- Installing sebastian/environment (5.1.3): Extracting archive
- Installing sebastian/diff (4.0.4): Extracting archive
- Installing sebastian/comparator (4.0.6): Extracting archive
- Installing sebastian/code-unit (1.0.8): Extracting archive
- Installing sebastian/cli-parser (1.0.1): Extracting archive
- Installing phpunit/php-timer (5.0.3): Extracting archive
- Installing phpunit/php-text-template (2.0.4): Extracting archive
- Installing phpunit/php-invoker (3.1.1): Extracting archive
- Installing phpunit/php-file-iterator (3.0.5): Extracting archive
- Installing theseer/tokenizer (1.2.1): Extracting archive
- Installing sebastian/lines-of-code (1.0.3): Extracting archive
- Installing sebastian/complexity (2.0.2): Extracting archive
- Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
- Installing phpunit/php-code-coverage (9.2.7): Extracting archive
- Installing doctrine/instantiator (1.4.0): Extracting archive
- Installing phpspec/prophecy (1.14.0): Extracting archive
- Installing phar-io/version (3.1.0): Extracting archive
- Installing phar-io/manifest (2.0.3): Extracting archive
- Installing myclabs/deep-copy (1.10.2): Extracting archive
- Installing phpunit/phpunit (9.5.10): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
InvalidArgumentException
Please provide a valid cache path.
at C:\Users\Artur\PhpstormProjects\stuttard.de\vendor\laravel\framework\src\Illuminate\View\Compilers\Compiler.php:36
32▕ */
33▕ public function __construct(Filesystem $files, $cachePath)
34▕ {
35▕ if (! $cachePath) {
➜ 36▕ throw new InvalidArgumentException('Please provide a valid cache path.');
37▕ }
38▕
39▕ $this->files = $files;
40▕ $this->cachePath = $cachePath;
1 C:\Users\Artur\PhpstormProjects\stuttard.de\vendor\laravel\framework\src\Illuminate\View\ViewServiceProvider.php:88
Illuminate\View\Compilers\Compiler::__construct(Object(Illuminate\Filesystem\Filesystem))
2 C:\Users\Artur\PhpstormProjects\stuttard.de\vendor\laravel\framework\src\Illuminate\Container\Container.php:873
Illuminate\View\ViewServiceProvider::Illuminate\View\{closure}(Object(Illuminate\Foundation\Application), [])
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
CodePudding user response:
Laravel needs to have a caching directory in order to store the compiled blade templates.
The path
is defined in config.view
file as follows:
'compiled' => env(
'VIEW_COMPILED_PATH',
realpath(storage_path('framework/views'))
),
As you might have noticed, Laravel looks at the VIEW_COMPILED_PATH
env variable first (if any), if it doesn't exist, then it falls back to storage/framework/views
.
If Laravel (for any reason) can't get the correct path, then it's going to throw an InvalidArgumentException
(check it out framework here).
For some reason, the compiled
path is wrong in your project.
It could be that the VIEW_COMPILED_PATH
env variable was set to an empty/null value:
VIEW_COMPILED_PATH=''
OR
VIEW_COMPILED_PATH=
More specifically, the compiled
entry returns an empty/null value, track it down and check out the returned value.
If the value is correct, then something else (such as Middleware) might have modified it.
But why composer fails?
When you run composer install/update
laravel uses composer script post-autoload-dump
to run php artisan package:discover
command.
The php artisan package:discover
command is going to rebuild the cached package manifest, therefore it hits the compiled views in order to clear them.
To solve the issue, you need to know why the config.view.compiled
entry returns an invalid value.
CodePudding user response:
Just run these commands and check.
php artisan optimize:clear
CodePudding user response:
Just run these commands and check.
php artisan cache:clear
php artisan config:clear
php artisan view:clear