Try manually deleting the contents of /bootstrap/cache (except .gitignore)
Target class Redis doesnt exist when installing telescope on Laravel 7
I'm currently trying to install telescope to be able to debug some performance bottleneck for a site in laravel 7.
Having installed telescope v3, I'm getting the following error
Target class [redis] does not exist.
Anyone familiar with what may be throwing this error? Looking through laracasts, I can see the suggestion to run php artisan config:clear but this fails with the same error as above. [1]
Any suggestions on how to proceed?
no dice there unfortunately. I've cleared both
- packages.php
- services.php
and re-ran composer install and I get the same error.
I cannot seem to recreate it locally in a laravel 7 install. What are you using redis for? What versions of packages are you using?
I tried with
- laravel 7.30.4
- telescope 3.5.1
- lighthouse 5.22.2
rereading my initial post, it telescope I'm having problem installing not lighthouse.
Yeah I noticed but installed both just to be sure :)
here's my full composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"type": "project",
"require": {
"php": "7.4.*",
"ext-json": "*",
"deepskylog/laravel-gettext": "^7.3.1",
"doctrine/dbal": "^2.11.1",
"dompdf/dompdf": "^0.8.6",
"ezyang/htmlpurifier": "^4.13.0",
"fruitcake/laravel-cors": "^2.0.2",
"google/apiclient": "2.7.2",
"laravel/framework": "7.26",
"laravel/passport": "^7.5.1",
"laravel/tinker": "^2.4.2",
"league/flysystem-aws-s3-v3": "^1.0.28",
"mnapoli/front-yaml": "^1.6.0",
"nyholm/psr7": "^1.3",
"ramsey/uuid": "^3.9.3",
"roave/security-advisories": "dev-master",
"rollbar/rollbar": "^2.1.0",
"shiftonelabs/laravel-sqs-fifo-queue": "^1.2.0",
"spatie/laravel-webhook-server": "^1.11",
"sqits/laravel-userstamps": "^0.0.8",
"stripe/stripe-php": "^7.56.0",
"tymon/jwt-auth": "^1.0.1",
"windwalker/renderer": "3.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.5",
"filp/whoops": "^2.7.3",
"fzaninotto/faker": "^1.9.1",
"laravel/dusk": "^5.11.0",
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^8.5.8",
"symfony/thanks": "^1.2.9",
"symfony/var-exporter": "^5.1.6",
"ext-gd": "*"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\": "app/"
},
"files": [
"includes/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"@php artisan package:discover"
],
"post-update-cmd": "Google_Task_Composer::cleanup"
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"github-oauth": {
"github.com": "REDACTED"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
AFAIK we're not using redis for anything. Its a legacy project that I've picked up so its entirely likely its defined somewhere in the project though.
I just installed a brand new laravel 7 installation, and replaced the composer.json with the above (with a few tweaks to get it working). And it ran artisan without any issues. Can you perhaps check your service providers or the includes/helpers.php file for any reference to 'redis' ?
sure.
Btw. It should be bound into the container here.
https://github.com/laravel/framework/blob/7.x/src/Illuminate/Foundation/Application.php#L1266
Also check app.php (in config) that you have this under aliases
'Redis' => Illuminate\Support\Facades\Redis::class,
and this under serviceproviders
Illuminate\Redis\RedisServiceProvider::class,
rereading my initial question, its telescope I'm having issue installing, not lighthouse.
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
- Downloading laravel/telescope (v3.0.0)
0/1 [>---------------------------] 0%
1/1 [============================] 100%
- Installing phpseclib/bcmath_compat (1.0.6): Extracting archive
- Installing moontoast/math (1.2.1): Extracting archive
- Installing laravel/telescope (v3.0.0): Extracting archive
0/3 [>---------------------------] 0%
1/3 [=========>------------------] 33%
2/3 [==================>---------] 66%
3/3 [============================] 100%
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package moontoast/math is abandoned, you should avoid using it. Use brick/math instead.
Package zendframework/zend-diactoros is abandoned, you should avoid using it. Use laminas/laminas-diactoros instead.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover
In Container.php line 811:
Target class [redis] does not exist.
In Container.php line 809:
Class redis does not exist
I'm running the following composer require laravel/telescope 3
Do a search for 'redis' in the whole app directory and includes directory :)
the only places redis is mentioned is within
- broadcasting.php
- cache.php
- database.php
- queue.php
- session.php
these look like default laravel settings.
Did you check the app.php file? Perhaps it has some wrong configuration? Like missing Redis, as mentioned above
app.php all looks pretty standard
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;
if its of any relevance, this site is being ran inside a docker container rather than on my local Mac. could it just be that there's no redis extension installed on php?
It should then fail on 'Redis' not 'redis'. And it would be the redis module. What if you run artisan outside of the container?
I can't run artisan outside of the container as I'm not running php7.4 on my Mac.
How about using a phpinfo.php file to check if the redis module is installed? Or php -m from the shell (inside the container)
searching within phpinfo, I see no reference to redis.
You can try installing it in the container perhaps? I am unsure if the issue is there but it could be worth a shot :)
Or use valet to install php7.4 locally to test that out :)
I'm have to bounce this off our devops guy to see if he can get redis installed for me within Dockerfile.
I can work round it for now, but will update this ticket once I've got redis on the container and see if that sorts it out.
Weirdly I recall this also being an issue on a clean laravel 8 project too - so suspect its docker related as they're using the same image.
The only time I can recall having problems like this, was when I had files inside /bootstrap/cache
Hi @automica
This Issue was not caused due to any Cache or vendor Issue. The reason for this Issue is due to the absence of Redis PECL Module in your PHP Installation.
Try to install that PECL Module and the Error will go away. This Issue is caused during the Post Autoload Dump phase of the Composer installation, while executing the php artisan package:discover Command specified in the composer.json scripts.
You can check the available PHP Modules using the command
php -m
@kingmaker_bgp So checking with our devops guy, he came back with:
we dont want to use PECL, its yet another repository to manage
So instead we've added the following to Dockerfile:
# install redis for telescope compatability
RUN pecl install redis
RUN docker-php-ext-enable redis
which gets past the Target class [redis] does not exist. error but now gives a new one:
In RedisWatcher.php line 21:
Call to undefined method Redis::connections()
with my best googling I found http://www.coding4developers.com/laravel/laravel-call-to-undefined-method-redisconnection/ which suggests
The Redis class is built-in to Laravel and connection() is there. It can't be missing. You might have installed php-redis on your system. Redis can be another class into php-redis. So there may conflict between Laravel Redis alias and another Redis class.
and suggests removing php-redis which is at odds to what we've done earlier.
Any suggestions on how to get this installed without relying on PECL?
Please or to participate in this conversation.