diff --git a/src/editor/js/structures/graph/graph.ts b/src/editor/js/structures/graph/graph.ts
index b9edda1baf3843dca436cac23e98f240acd0af8e..566589a8a16eded8142f3ad037f89ecc2983388d 100644
--- a/src/editor/js/structures/graph/graph.ts
+++ b/src/editor/js/structures/graph/graph.ts
@@ -304,9 +304,9 @@ export class Graph extends ManagedData {
             // No need to replace node ids with proper node objects, since that should be done in the graph itself. Only have to prepare valid GraphData
         });
 
-        // Collect all node types and give id of none given yet
+        // Collect all node types and give id if none given yet
         let typeId: number = undefined;
-        if (data.nodes[0].type.id === undefined) {
+        if (data.nodes.length > 0 && data.nodes[0].type.id === undefined) {
             typeId = 0;
         }