{"record":{"id":"040a87375c53c8fa","repo":"remotion-dev/remotion","slug":"cannot-create-path-relative-remotionroot-componentfilepath","errorCode":null,"errorMessage":"Cannot create ${path.relative(\n\t\t\t\t\t\t\tremotionRoot,\n\t\t\t\t\t\t\tcomponentFilePath,\n\t\t\t\t\t\t)} because it already exists","messagePattern":"Cannot create (.+?) because it already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-server/src/preview-server/routes/insert-element.ts","lineNumber":162,"sourceCode":"\t\t\t\tif (registrationFilePath === null) {\n\t\t\t\t\tthrow new Error('Cannot find file for composition in project');\n\t\t\t\t}\n\n\t\t\t\tcheckIfTypeScriptFile(registrationFilePath);\n\t\t\t\tif (\n\t\t\t\t\tpath.resolve(remotionRoot, compositionFile) !== registrationFilePath\n\t\t\t\t) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'New composition source does not match installation target',\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst componentFilePath = path.join(\n\t\t\t\t\tpath.dirname(registrationFilePath),\n\t\t\t\t\t`${newComposition.codemod.componentName}.tsx`,\n\t\t\t\t);\n\t\t\t\tif (existsSync(componentFilePath)) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot create ${path.relative(\n\t\t\t\t\t\t\tremotionRoot,\n\t\t\t\t\t\t\tcomponentFilePath,\n\t\t\t\t\t\t)} because it already exists`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst registrationFileOldContents = readFileSync(\n\t\t\t\t\tregistrationFilePath,\n\t\t\t\t\t'utf-8',\n\t\t\t\t);\n\t\t\t\tconst registrationFileNewContents = await applyCodemodToFile({\n\t\t\t\t\tfilePath: registrationFilePath,\n\t\t\t\t\tcodeMod: newComposition.codemod,\n\t\t\t\t});\n\t\t\t\tconst componentFileContents = await formatNewCompositionFile(\n\t\t\t\t\tnewComposition.codemod,\n\t\t\t\t);","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-server/src/preview-server/routes/insert-element.ts#L144-L180","documentation":"When a new composition is created, the route generates a component file <componentName>.tsx next to the registration file. If a file at that path already exists on disk, creating it would overwrite user code, so the route throws with the relative path of the offending file.","triggerScenarios":"POSTing to insert-element with newComposition.codemod.componentName matching a file that already exists in the registration file's directory (path.dirname(registrationFilePath)/<componentName>.tsx).","commonSituations":"Re-inserting an element with the same generated component name after a previous partial installation, or the generated name colliding with an existing component file the user wrote by hand.","solutions":["Choose a different component name / installationName so the generated file is unique","Delete or rename the existing <componentName>.tsx if it is a leftover artifact","Complete the previously interrupted insert (which may have left the file behind) before retrying"],"exampleFix":"// before\nnewComposition.codemod.componentName = 'MyTitle'; // src/MyTitle.tsx already exists\n// after\nnewComposition.codemod.componentName = 'MyTitle2';","handlingStrategy":"validation","validationCode":"const componentFile = path.join(path.dirname(registrationFilePath), componentName + '.tsx');\nif (existsSync(componentFile)) {\n  componentName = componentName + '-' + Date.now(); // or abort\n}","typeGuard":null,"tryCatchPattern":"try {\n  await insertElement(payload);\n} catch (e) {\n  if (/because it already exists/.test(e.message)) {\n    payload.newComposition.codemod.componentName = uniquify(payload.newComposition.codemod.componentName);\n  }\n}","preventionTips":["Check existsSync on the target component path before inserting","Use unique installation names to avoid component name collisions","Clean up leftovers from previously interrupted insertions"],"tags":["insert-element","file-conflict","filesystem"],"backgroundTag":"file-already-exists","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-18T00:12:20.256Z","contentChangedAt":"2026-09-18T00:12:20.256Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}