在 Laravel 6 中报错:Target [Interface] is not instantiable while building [Resolver]

1、在 Laravel 6 中报错:Target [Interface] is not instantiable while building [Resolver]。如图1

图1

{
    "message": "Target [Modules\\ThemeSetting\\Schema\\ThemeConfigLoaderInterface] is not instantiable while building [Modules\\ThemeStore\\Resolver\\OnlineStoreThemeResolver].",
    "exception": "Illuminate\\Contracts\\Container\\BindingResolutionException",
    "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
    "line": 978,
    "trace": [
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 812,
            "function": "notInstantiable",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 681,
            "function": "build",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php",
            "line": 785,
            "function": "resolve",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 629,
            "function": "resolve",
            "class": "Illuminate\\Foundation\\Application",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php",
            "line": 770,
            "function": "make",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 945,
            "function": "make",
            "class": "Illuminate\\Foundation\\Application",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 873,
            "function": "resolveClass",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 834,
            "function": "resolveDependencies",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 681,
            "function": "build",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php",
            "line": 785,
            "function": "resolve",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php",
            "line": 629,
            "function": "resolve",
            "class": "Illuminate\\Foundation\\Application",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php",
            "line": 770,
            "function": "make",
            "class": "Illuminate\\Container\\Container",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\helpers.php",
            "line": 120,
            "function": "make",
            "class": "Illuminate\\Foundation\\Application",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Utils.php",
            "line": 58,
            "function": "app"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Schema\\Directives\\FieldDirective.php",
            "line": 45,
            "function": "constructResolver",
            "class": "Nuwave\\Lighthouse\\Support\\Utils",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Schema\\Factories\\FieldFactory.php",
            "line": 68,
            "function": "resolveField",
            "class": "Nuwave\\Lighthouse\\Schema\\Directives\\FieldDirective",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Schema\\TypeRegistry.php",
            "line": 369,
            "function": "handle",
            "class": "Nuwave\\Lighthouse\\Schema\\Factories\\FieldFactory",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Type\\Definition\\UnresolvedFieldDefinition.php",
            "line": 39,
            "function": "Nuwave\\Lighthouse\\Schema\\{closure}",
            "class": "Nuwave\\Lighthouse\\Schema\\TypeRegistry",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Type\\Definition\\TypeWithFields.php",
            "line": 45,
            "function": "resolve",
            "class": "GraphQL\\Type\\Definition\\UnresolvedFieldDefinition",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Type\\Definition\\TypeWithFields.php",
            "line": 33,
            "function": "findField",
            "class": "GraphQL\\Type\\Definition\\TypeWithFields",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Validator\\Rules\\OverlappingFieldsCanBeMerged.php",
            "line": 256,
            "function": "getField",
            "class": "GraphQL\\Type\\Definition\\TypeWithFields",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Validator\\Rules\\OverlappingFieldsCanBeMerged.php",
            "line": 165,
            "function": "internalCollectFieldsAndFragmentNames",
            "class": "GraphQL\\Validator\\Rules\\OverlappingFieldsCanBeMerged",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Validator\\Rules\\OverlappingFieldsCanBeMerged.php",
            "line": 96,
            "function": "getFieldsAndFragmentNames",
            "class": "GraphQL\\Validator\\Rules\\OverlappingFieldsCanBeMerged",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Validator\\Rules\\OverlappingFieldsCanBeMerged.php",
            "line": 64,
            "function": "findConflictsWithinSelectionSet",
            "class": "GraphQL\\Validator\\Rules\\OverlappingFieldsCanBeMerged",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Language\\Visitor.php",
            "line": 414,
            "function": "GraphQL\\Validator\\Rules\\{closure}",
            "class": "GraphQL\\Validator\\Rules\\OverlappingFieldsCanBeMerged",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Language\\Visitor.php",
            "line": 470,
            "function": "GraphQL\\Language\\{closure}",
            "class": "GraphQL\\Language\\Visitor",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Language\\Visitor.php",
            "line": 277,
            "function": "GraphQL\\Language\\{closure}",
            "class": "GraphQL\\Language\\Visitor",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Validator\\DocumentValidator.php",
            "line": 224,
            "function": "visit",
            "class": "GraphQL\\Language\\Visitor",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\Validator\\DocumentValidator.php",
            "line": 116,
            "function": "visitUsingRules",
            "class": "GraphQL\\Validator\\DocumentValidator",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\GraphQL.php",
            "line": 153,
            "function": "validate",
            "class": "GraphQL\\Validator\\DocumentValidator",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\webonyx\\graphql-php\\src\\GraphQL.php",
            "line": 94,
            "function": "promiseToExecute",
            "class": "GraphQL\\GraphQL",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
            "line": 268,
            "function": "executeQuery",
            "class": "GraphQL\\GraphQL",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
            "line": 203,
            "function": "executeParsedQuery",
            "class": "Nuwave\\Lighthouse\\GraphQL",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
            "line": 162,
            "function": "parseAndExecuteQuery",
            "class": "Nuwave\\Lighthouse\\GraphQL",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
            "line": 121,
            "function": "executeOperation",
            "class": "Nuwave\\Lighthouse\\GraphQL",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Utils.php",
            "line": 99,
            "function": "Nuwave\\Lighthouse\\{closure}",
            "class": "Nuwave\\Lighthouse\\GraphQL",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\GraphQL.php",
            "line": 120,
            "function": "applyEach",
            "class": "Nuwave\\Lighthouse\\Support\\Utils",
            "type": "::"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Controllers\\GraphQLController.php",
            "line": 32,
            "function": "executeOperationOrOperations",
            "class": "Nuwave\\Lighthouse\\GraphQL",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php",
            "line": 48,
            "function": "__invoke",
            "class": "Nuwave\\Lighthouse\\Support\\Http\\Controllers\\GraphQLController",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
            "line": 219,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
            "line": 176,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 681,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Middleware\\AttemptAuthentication.php",
            "line": 34,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AttemptAuthentication",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\nuwave\\lighthouse\\src\\Support\\Http\\Middleware\\AcceptJson.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Nuwave\\Lighthouse\\Support\\Http\\Middleware\\AcceptJson",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 683,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 658,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 624,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
            "line": 613,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 170,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 130,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\barryvdh\\laravel-debugbar\\src\\Middleware\\InjectDebugbar.php",
            "line": 67,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\app\\Http\\Middleware\\ChangeAppUrlMiddleware.php",
            "line": 23,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "App\\Http\\Middleware\\ChangeAppUrlMiddleware",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php",
            "line": 63,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\fideloper\\proxy\\src\\TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\dingo\\api\\src\\Http\\Middleware\\Request.php",
            "line": 111,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 171,
            "function": "handle",
            "class": "Dingo\\Api\\Http\\Middleware\\Request",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php",
            "line": 105,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 145,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php",
            "line": 110,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "E:\\wwwroot\\object\\public\\index.php",
            "line": 57,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}

2、查看 Git 日志,分析 /Modules/ThemeStore/Providers/ThemeStoreServiceProvider.php,发现之前有在容器中注册一个共享绑定:ThemeConfigLoaderInterface::class,但是现在已经不存在。如图2

图2

        $this->app->singleton(ThemeConfigLoaderInterface::class, function($app) {
            if ($this->app['config']['theme_store.view_storage'] == 'database') {
                return new DbThemeSchemaLoader($app->make(ThemeBuilder::class), $app->make(ThemeSettingBuilder::class), $app->make(ViewStorageInterface::class));
            } else {
                return new FileThemeSchemaLoader($app->make('igaster.themes'), $app->make(ThemeBuilder::class), $app->make(ThemeSettingBuilder::class));
            }
        });
        $this->app->singleton(ThemeConfigSourceInterface::class, function($app) {
            if ($this->app['config']['theme_store.view_storage'] == 'database') {
                return new ThemeConfigDbSource($app->make(ViewStorageInterface::class), $this->app['files'], $this->app['config']['view.compiled']);
            } else {
                return new ThemeConfigFileSource($app->make('igaster.themes'));
            }
        });

3、最后发现此共享绑定:ThemeConfigLoaderInterface::class 已经移至 /Modules/ThemeSetting/Providers/ThemeSettingServiceProvider.php

        $this->app->singleton(ThemeConfigLoaderInterface::class, function ($app) {
            return new ThemeConfigLoader($app->make(ThemeBuilder::class), $app->make(ThemeSettingBuilder::class), $app->make(RawThemeConfigProvider::class));
        });

4、编辑 /config/app.php,在 ThemeStoreServiceProvider::class 之前添加 ThemeSettingServiceProvider::class


    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Modules\ThemeSetting\Providers\ThemeSettingServiceProvider::class,
        Modules\ThemeStore\Providers\ThemeStoreServiceProvider::class,

    ],

5、再次请求,响应 200。如图3

图3

永夜