Skip to main content

duplicateNodes()v4.0.530

Duplicates one or more source nodes.

warning

Draft API: This API is experimental and may change.

duplicate-nodes.ts
import {duplicateNodes, type CodemodProject, type NodeReference} from '@remotion/codemods'; declare const project: CodemodProject; declare const node: NodeReference; const result = await duplicateNodes({ project, nodes: [node], }); console.log(result);

Copies the node's source, including props and children. Imported component implementations remain shared. Overlapping ancestor/descendant selections are unsupported.

Since v4.0.540, a clip directly inside a <Track>, optionally grouped with anonymous fragments (<>...</>), is copied into a new sibling <Track> with its timing preserved. Multiple selected clips from one track share one new track. The new track preserves the original track's props except its explicit React key and adds -copy to a static name.

Options​

project​

An in-memory CodemodProject. The input project is not mutated.

nodes​

The node references to duplicate. They may belong to different files. All references are resolved against the input project; duplicate references are deduplicated.

Return value​

A promise resolving to an object with the following properties.

changes​

An array of {filePath, previousContents, nextContents} file changes. A null content value indicates a created or deleted file.

nodePathRemappings​

An array of {filePath, oldNodePath, newNodePath} mappings. A null old path indicates an insertion; a null new path indicates removal. Apply these mappings to references from the input project. See node references.

insertedNodes​

References to the inserted roots, in source order within each file. When duplicating clips from a <Track>, these references identify the new track wrappers. Descendant references are included in nodePathRemappings.

duplicatedNodesv4.0.540​

References to the copies of the requested nodes. For clips copied into a new <Track>, these identify the copied clips rather than the track wrapper. Use these references to edit the copies afterward.

Errors​

Throws or rejects when the target cannot be resolved, the requested edit is unsupported, or an option is invalid. Failed edits leave the input project unchanged.

Clips inside an intervening element or expression within a <Track>, including named React fragments, cannot be copied into a separate track. Duplicate the enclosing track instead, or make the clip a direct child of the track.

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​