{"record":{"id":"9e060468a4155f38","repo":"remotion-dev/remotion","slug":"cannot-create-relativetoroot-componentfilepath","errorCode":null,"errorMessage":"Cannot create ${relativeToRoot(componentFilePath, project.rootDir)} because it already exists","messagePattern":"Cannot create (.+?) because it already exists","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-studio/src/browser-studio-operations.ts","lineNumber":1438,"sourceCode":"\n\t\t\tconst project = getProject();\n\t\t\tconst absolutePath = resolveCodemodTargetFile({\n\t\t\t\tcodemod,\n\t\t\t\tproject,\n\t\t\t\tsymbolicatedStack,\n\t\t\t});\n\t\t\tconst input = project.files[absolutePath];\n\t\t\tconst {newContents} = parseAndApplyCodemod({input, codeMod: codemod});\n\t\t\tconst {output} = await formatCodemodFile({contents: newContents});\n\t\t\tconst files: Record<string, string> = {\n\t\t\t\t...project.files,\n\t\t\t\t[absolutePath]: output,\n\t\t\t};\n\n\t\t\tif (codemod.type === 'new-composition') {\n\t\t\t\tconst componentFilePath = `${dirname(absolutePath)}/${codemod.componentName}.tsx`;\n\t\t\t\tif (project.files[componentFilePath] !== undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot create ${relativeToRoot(componentFilePath, project.rootDir)} because it already exists`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst componentFile = await formatCodemodFile({\n\t\t\t\t\tcontents: makeNewCompositionComponentSource(codemod.componentName),\n\t\t\t\t});\n\t\t\t\tfiles[componentFilePath] = componentFile.output;\n\t\t\t}\n\n\t\t\tconst diff = simpleDiff({\n\t\t\t\toldLines: input.split('\\n'),\n\t\t\t\tnewLines: output.split('\\n'),\n\t\t\t});\n\n\t\t\tif (!dryRun) {\n\t\t\t\tcontroller.applyMutation({\n\t\t\t\t\tfileName: absolutePath,","sourceCodeStart":1420,"sourceCodeEnd":1456,"githubUrl":"https://github.com/remotion-dev/remotion/blob/8f9775815716e25b2a9fd9c5511015a17624243d/packages/browser-studio/src/browser-studio-operations.ts#L1420-L1456","documentation":"Thrown by the applyCodemod operation of @remotion/browser-studio when a 'new-composition' codemod tries to generate the new component file `${componentName}.tsx` next to the resolved target file, but that exact path already exists in the virtual project's file map. Browser Studio never overwrites existing files with scaffolded composition components, so it aborts the whole codemod. The error is caught inside applyCodemod and returned as `{success: false, reason}` rather than propagated.","triggerScenarios":"Calling `applyCodemod({codemod: {type: 'new-composition', componentName: 'MyComp', ...}})` when `${dirname(targetFile)}/MyComp.tsx` is already a key in `project.files`. Note the check uses the literal componentName, so a second call with the same name after a successful first call always fails.","commonSituations":"User creates a composition with the same name twice in one session; a UI retry after a partial success re-submits the same componentName; componentName differs from an existing file only by letter case; a previously deleted composition left its .tsx file behind.","solutions":["Pick a different, unused componentName for the new composition","Delete or rename the existing `<componentName>.tsx` in the project files before re-running the codemod","List `project.files` (or use the file APIs) to confirm which paths are taken before submitting","If you genuinely want to regenerate the file, write it yourself via the project mutation API — applyCodemod has no overwrite flag"],"exampleFix":"// before\nawait operations.applyCodemod({\n  codemod: {type: 'new-composition', componentName: 'Intro', /* ... */},\n  dryRun: false,\n  symbolicatedStack: null,\n}); // fails if Intro.tsx exists\n\n// after\nconst project = operations.getProject ? operations.getProject() : null;\n// or track files from a project event; guard before creating\nconst base = `${rootDir}/src`;\nif (project?.files[`${base}/Intro.tsx`] !== undefined) {\n  throw new Error('Pick another name, Intro.tsx already exists');\n}\nawait operations.applyCodemod({\n  codemod: {type: 'new-composition', componentName: 'Intro2', /* ... */},\n  dryRun: false,\n  symbolicatedStack: null,\n});","handlingStrategy":"validation","validationCode":"const componentFilePath = `${dirOfTargetFile}/${componentName}.tsx`;\nif (project.files[componentFilePath] !== undefined) {\n  // pick another name or delete the file first\n  throw new Error(`${componentFilePath} already exists`);\n}\nconst res = await operations.applyCodemod({codemod, dryRun: false, symbolicatedStack: null});\nif (!res.success) console.error(res.reason);","typeGuard":null,"tryCatchPattern":"applyCodemod does not throw for this case — check `res.success === false` and read `res.reason`. Only wrap for unexpected coding errors.","preventionTips":["Derive componentName from the current file list and disambiguate (MyComp2) before submitting","After any deletion flow, refresh your cached list of project files","Treat dryRun responses as authoritative previews of whether the real call will succeed"],"tags":["file-system","codemod","compositions","browser-studio"],"backgroundTag":"file-already-exists","analyzedSha":"8f9775815716e25b2a9fd9c5511015a17624243d","analyzedAt":"2026-08-22T21:45:17.748Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}