{"id":"70bf8bd65bb869d7","repo":"laravel/framework","slug":"target-concrete-is-not-instantiable-while-build","errorCode":null,"errorMessage":"Target [$concrete] is not instantiable while building [$previous].","messagePattern":"Target \\[\\$concrete\\] is not instantiable while building \\[\\$previous\\]\\.","errorType":"exception","errorClass":"BindingResolutionException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Container/Container.php","lineNumber":1436,"sourceCode":"    /**\n     * Throw an exception that the concrete is not instantiable.\n     *\n     * @param  string  $concrete\n     * @return void\n     *\n     * @throws \\Illuminate\\Contracts\\Container\\BindingResolutionException\n     */\n    protected function notInstantiable($concrete)\n    {\n        if (! empty($this->buildStack)) {\n            $previous = implode(', ', $this->buildStack);\n\n            $message = \"Target [$concrete] is not instantiable while building [$previous].\";\n        } else {\n            $message = \"Target [$concrete] is not instantiable.\";\n        }\n\n        throw new BindingResolutionException($message);\n    }\n\n    /**\n     * Throw an exception for an unresolvable primitive.\n     *\n     * @return void\n     *\n     * @throws \\Illuminate\\Contracts\\Container\\BindingResolutionException\n     */\n    protected function unresolvablePrimitive(ReflectionParameter $parameter)\n    {\n        $message = \"Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}\";\n\n        throw new BindingResolutionException($message);\n    }\n\n    /**\n     * Register a new before resolving callback for all types.","sourceCodeStart":1418,"sourceCodeEnd":1454,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Container/Container.php#L1418-L1454","documentation":"Thrown by Container::notInstantiable when the concrete being built (an interface, abstract class, or trait) is not instantiable AND the buildStack is non-empty — meaning the failure occurred while resolving a dependency of another class. The message lists the chain of classes currently being built so you can see which dep caused it.","triggerScenarios":"Resolving class A whose constructor requires interface B that has no concrete binding: getConcrete returns B, build() reflects B, isInstantiable() is false, buildStack contains A → message 'Target [B] is not instantiable while building [A].'","commonSituations":"Forgetting to bind an interface to a concrete in a service provider; refactor replacing a class with an interface without updating bindings; scoped/singleton binding lost after clearing the container; testing without registering the test doubles in the container.","solutions":["Bind the interface to a concrete: $this->app->bind(Contract::class, Implementation::class).","Inspect the 'while building [...]' list to find which dependent class pulls in the non-instantiable type and fix its binding.","Use $this->app->bind(Contract::class, fn () => $mock) in tests to supply a fake.","Make sure your ServiceProvider is registered in config/app.php (or discovered) so the binding runs."],"exampleFix":"// before\n// App\\Contracts\\Payment has no binding\napp()->make(OrderProcessor::class);\n\n// after\n// in AppServiceProvider::register\n$this->app->bind(\\App\\Contracts\\Payment::class, \\App\\Services\\StripePayment::class);","handlingStrategy":"validation","validationCode":"$reflection = new \\ReflectionClass($concrete);\nif (! $reflection->isInstantiable() && ! app()->bound($concrete)) {\n    throw new \\LogicException(\"{$concrete} is not instantiable; bind it first\");\n}","typeGuard":"function isInstantiableOrBound(string $class, \\Illuminate\\Container\\Container $c): bool\n{\n    if ($c->bound($class)) return true;\n    return (new \\ReflectionClass($class))->isInstantiable();\n}","tryCatchPattern":"use Illuminate\\Contracts\\Container\\BindingResolutionException;\ntry {\n    app()->make($service);\n} catch (BindingResolutionException $e) {\n    if (str_contains($e->getMessage(), 'is not instantiable while building')) {\n        // bind missing interface then retry\n    }\n    throw $e;\n}","preventionTips":["Bind every interface in a service provider.","Use phpstan with template/contract checking.","Write container compilation tests that resolve all root services."],"tags":["container","binding","interface","di","dependency-injection"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}