{"record":{"id":"5f3eb19cf24a77f3","repo":"apify/crawlee","slug":"serviceconflicterror-configuration-configuratio","errorCode":null,"errorMessage":"ServiceConflictError('Configuration', configuration, this.#configuration)","messagePattern":"ServiceConflictError\\('Configuration', configuration, this\\.#configuration\\)","errorType":"exception","errorClass":"ServiceConflictError","httpStatus":null,"severity":"error","filePath":"packages/core/src/service_locator.ts","lineNumber":201,"sourceCode":"    }\n\n    getConfiguration(): Configuration {\n        if (!this.#configuration) {\n            this.getLogger().debug('No configuration set, implicitly creating and using default Configuration.');\n            this.#configuration = new Configuration();\n        }\n        return this.#configuration;\n    }\n\n    setConfiguration(configuration: Configuration): void {\n        // Same instance, no need to do anything\n        if (this.#configuration === configuration) {\n            return;\n        }\n\n        // Already have a different configuration that was retrieved\n        if (this.#configuration) {\n            throw new ServiceConflictError('Configuration', configuration, this.#configuration);\n        }\n\n        this.#configuration = configuration;\n    }\n\n    getEventManager(): EventManager {\n        if (!this.#eventManager) {\n            this.getLogger().debug('No event manager set, implicitly creating and using default LocalEventManager.');\n            if (!this.#configuration) {\n                this.getLogger().warning(\n                    'Implicit creation of event manager will implicitly set configuration as side effect. ' +\n                        'It is advised to explicitly first set the configuration instead.',\n                );\n            }\n            this.#eventManager = LocalEventManager.fromConfiguration(this.getConfiguration());\n        }\n        return this.#eventManager;\n    }","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/service_locator.ts#L183-L219","documentation":"ServiceLocator allows each service to be registered at most once. setConfiguration() throws ServiceConflictError when a different Configuration instance is provided after one has already been set/retrieved. Identical instances are idempotent (no-op), so this only fires on genuine conflicts between two distinct Configuration objects.","triggerScenarios":"Calling locator.setConfiguration(cfgA) (or retrieving configuration via getConfiguration()) and then calling locator.setConfiguration(cfgB) with a different Configuration instance.","commonSituations":"Initializing crawlee twice in one process (e.g. in tests or HMR reloads), globalConfiguration vs. a manually built Configuration, or a module importing crawlee under two different paths so two Configuration instances exist.","solutions":["Ensure setConfiguration() is called only once, before any service is retrieved from the locator.","Pass the same Configuration instance consistently; do not build a new Configuration for a second call.","Create a fresh ServiceLocator (or reset it) if you truly need to swap configurations.","In tests, isolate the locator per test or clear module state between tests to avoid stale registrations."],"exampleFix":"// before\nConfiguration.global.set('storageOptions', opts);\nlocator.setConfiguration(new Configuration()); // conflicts\n\n// after\nconst config = Configuration.getGlobalConfig();\nconfig.set('storageOptions', opts);\nlocator.setConfiguration(config); // same instance, no conflict","handlingStrategy":"validation","validationCode":"if (locator.getConfiguration && locator.getConfiguration() !== myConfig) {\n    // a different configuration already registered – do not call setConfiguration again\n}","typeGuard":null,"tryCatchPattern":"try {\n    locator.setConfiguration(config);\n} catch (e) {\n    if (e instanceof ServiceConflictError) {\n        console.warn('Configuration already set; reusing existing one.');\n    } else throw e;\n}","preventionTips":["Call setConfiguration() exactly once at process startup.","Reuse Configuration.getGlobalConfig() instead of constructing new instances.","In tests, create a fresh ServiceLocator per test."],"tags":["configuration","dependency-injection","lifecycle"],"backgroundTag":"service-already-configured","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}