{"record":{"id":"a52eacbae5e69d60","repo":"pubkey/rxdb","slug":"db8","errorCode":"DB8","errorMessage":"RxDB Error-Code: DB8. Hint: Error messages are not included in RxDB core to reduce build size. To show the full error messages and to ensure that you do not make any mistakes when using RxDB, use the dev-mode plugin when you are in development mode: https://rxdb.info/dev-mode.html?console=error","messagePattern":"RxDB Error-Code: DB8\\. Hint: Error messages are not included in RxDB core to reduce build size\\. To show the full error messages and to ensure that you do not make any mistakes when using RxDB, use the dev-mode plugin when you are in development mode: https://rxdb\\.info/dev-mode\\.html\\?console=error","errorType":"error_code","errorClass":"RxError","httpStatus":null,"severity":"error","filePath":"src/rx-database.ts","lineNumber":707,"sourceCode":"    > {\n        return this as any;\n    }\n\n    registerWebMCP(_options?: WebMCPOptions): { error$: Subject<Error>; log$: Subject<WebMCPLogEvent>; } {\n        throw pluginMissing('webmcp');\n    }\n}\n\n/**\n * checks if an instance with same name and storage already exists\n * @throws {RxError} if used\n */\nfunction throwIfDatabaseNameUsed(\n    name: string,\n    storage: RxStorage<any, any>\n) {\n    if (USED_DATABASE_NAMES.has(getDatabaseNameKey(name, storage))) {\n        throw newRxError('DB8', {\n            name,\n            storage: storage.name,\n            link: 'https://rxdb.info/rx-database.html#ignoreduplicate'\n        });\n    }\n}\n\n/**\n * Polyfill for https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers\n */\nfunction createPromiseWithResolvers<T>() {\n    let resolve!: (value: T | PromiseLike<T>) => void;\n    let reject!: (reason?: any) => void;\n    const promise = new Promise<T>((res, rej) => {\n        resolve = res;\n        reject = rej;\n    });\n    return { promise, resolve, reject };","sourceCodeStart":689,"sourceCodeEnd":725,"githubUrl":"https://github.com/pubkey/rxdb/blob/af6fb65f94cd70558d74c23799eda11ff1c15224/src/rx-database.ts#L689-L725","documentation":"DB8 is thrown when you call createRxDatabase() with a name+storage combination that is already in use in the current process. RxDB keeps a global registry (USED_DATABASE_NAMES) of every created database per storage to prevent two RxDatabase instances from writing to the same underlying storage, which would corrupt change detection and replication. The registry entry is only cleared when the database is closed.","triggerScenarios":"Calling createRxDatabase() a second time with the same name and same RxStorage instance, e.g. re-running an init function on hot reload, or after an earlier createRxDatabase() call was not closed before retrying.","commonSituations":"Hot module reloading in dev servers that re-executes database setup code; test suites that create the same database in beforeEach without closing the previous one; accidental double-invocation of an async init function (e.g. React StrictMode double effects); calling createRxDatabase after a failed creation left the name registered.","solutions":["Close the existing database before re-creating: await oldDatabase.close() (or call remove() to also delete its data).","Keep the database instance in a module-level singleton and reuse it instead of calling createRxDatabase again.","If you intentionally want to recreate with the same name, pass { ignoreDuplicate: true } to createRxDatabase in dev mode (requires the dev-mode plugin, see DB9).","Fix hot-reload/test setup to await creation and close databases in cleanup hooks."],"exampleFix":"// before\nconst db = await createRxDatabase({ name: 'mydb', storage: getRxStorageDexie() });\n// after\nlet dbPromise;\nexport function getDb() {\n  if (!dbPromise) {\n    dbPromise = createRxDatabase({ name: 'mydb', storage: getRxStorageDexie() });\n  }\n  return dbPromise;\n}","handlingStrategy":"try-catch","validationCode":"import { getRxStorageDexie } from 'rxdb/plugins/storage-dexie';\n// keep a module-level handle so you can check/close before recreating\nexport let dbInstance;\nexport async function ensureClosed() {\n  if (dbInstance && !dbInstance.closed) {\n    await dbInstance.close();\n    dbInstance = undefined;\n  }\n}","typeGuard":"function canCreate(db) {\n  return !dbInstance || dbInstance.closed || dbInstance.name !== db.name;\n}","tryCatchPattern":"try {\n  dbInstance = await createRxDatabase({ name: 'mydb', storage });\n} catch (err) {\n  if (String(err?.code) === 'DB8') {\n    await dbInstance?.close();\n    dbInstance = await createRxDatabase({ name: 'mydb', storage });\n  } else {\n    throw err;\n  }\n}","preventionTips":["Store the RxDatabase instance in a singleton and reuse it instead of recreating.","Always await database.close() or remove() in test teardown and hot-reload cleanup.","Guard init functions against double invocation (memoize the promise).","Never recreate a database with the same name+storage in the same process without closing."],"tags":["database","duplicate-instance","initialization"],"backgroundTag":"duplicate-database-instance","analyzedSha":"af6fb65f94cd70558d74c23799eda11ff1c15224","analyzedAt":"2026-08-31T23:32:37.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}