{"record":{"id":"04c606abcdf4d1e4","repo":"hcengineering/platform","slug":"project-not-found-projectid","errorCode":null,"errorMessage":"Project not found: ${projectId}","messagePattern":"Project not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/importer/src/importer/importer.ts","lineNumber":469,"sourceCode":"    return id\n  }\n\n  async importProject (project: ImportProject): Promise<Ref<Project>> {\n    let projectId: Ref<Project>\n    if (project.id === tracker.project.DefaultProject) {\n      this.logger.log('Setting up default project: ' + project.title)\n      projectId = tracker.project.DefaultProject\n      await this.updateProject(projectId, project)\n      this.logger.log('Default project updated: ' + projectId)\n    } else {\n      this.logger.log('Creating project: ', project.title)\n      projectId = await this.createProject(project)\n      this.logger.log('Project created: ' + projectId)\n    }\n\n    const projectDoc = await this.client.findOne(tracker.class.Project, { _id: projectId })\n    if (projectDoc === undefined) {\n      throw new Error('Project not found: ' + projectId)\n    }\n\n    // Create Component / Milestone docs declared on the\n    // project. The maps keep them addressable by label for later\n    // resolution from issue front-matter.\n    const componentIds = new Map<string, Ref<any>>()\n    const milestoneIds = new Map<string, Ref<any>>()\n    if (project.components !== undefined) {\n      for (const c of project.components) {\n        const id = generateId()\n        await this.client.createDoc(\n          tracker.class.Component,\n          projectId,\n          {\n            label: c.label,\n            description: c.description ?? '',\n            lead: null,\n            comments: 0,","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/packages/importer/src/importer/importer.ts#L451-L487","documentation":"importProject first finds or creates the project, then re-reads it from the backing store with client.findOne(tracker.class.Project, {_id: projectId}). If the document is not found even after creation, the store is inconsistent and the importer aborts with 'Project not found: <id>'.","triggerScenarios":"client.findOne returns undefined for the projectId — the project was deleted between creation and lookup, the projectId passed to importProject never existed (stale/wrong Ref), or createProject silently failed while still returning an id.","commonSituations":"Rerunning a partially completed import against a workspace where the project was later removed; passing a projectId string that refers to a project in a different workspace; permissions/db replication lag in a distributed backend.","solutions":["Verify the projectId comes from the same workspace the client is connected to","Confirm the project still exists in the target workspace before importing (findOne yourself)","If createProject returned an id, check server logs for a failed/persisted create transaction","Delete stale import state and re-run the import from scratch so projects are recreated"],"exampleFix":"// before\nawait importer.importProject('nonexistent-project-id' as Ref<Project>, project)\n// after\nconst existing = await client.findOne(tracker.class.Project, { _id: projectId })\nif (existing === undefined) {\n  projectId = await importer.importProject(undefined, project) // let it create\n}","handlingStrategy":"validation","validationCode":"const existing = await client.findOne(tracker.class.Project, { _id: projectId })\nif (existing === undefined) {\n  throw new Error(`Refusing to import: project ${projectId} does not exist in this workspace`)\n}","typeGuard":"function projectRef(v: unknown): v is Ref<Project> {\n  return typeof v === 'string' && v.length > 0\n}","tryCatchPattern":"try {\n  await importer.importProject(projectId, project)\n} catch (err) {\n  if (err.message.startsWith('Project not found:')) {\n    // recreate then retry\n    await importer.importProject(undefined, project)\n  } else throw err\n}","preventionTips":["Always fetch project ids fresh from the connected workspace instead of caching across runs","Confirm client connection/workspace matches the ids you pass","Never assume createProject persisted — verify with findOne before continuing","Avoid deleting target projects between incremental import runs"],"tags":["importer","project-not-found","data-consistency"],"backgroundTag":"resource-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}