<% if collage.present? -%>
<div class="collage-content" id="collage<%= collage.id %>" data-id="<%= collage.id %>">
  <div class="article">
    <% cache(["printable-content", collage.annotatable], :expires_in => 2.weeks, :compress => H2O_CACHE_COMPRESSION) do %>
      <%= raw collage.printable_content %>
    <% end -%>
  </div>
</div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  export_functions.initiate_collage_data(<%= collage.id %>, {
    data: <%= raw(params[:state] || collage.readable_state || "{}") %>,
    annotations: <%= raw collage.annotations_as_export_json %>,
    layer_data: <%= raw collage.layer_data.to_json %>,
    highlights_only: <%= raw collage.highlights_only.to_json %>,
  });
});
</script>
<% end -%>

<% if collage.present? -%>
<div class="collage-content" id="collage<%= collage.id %>" data-id="<%= collage.id %>">
  <div class="article">
    <% cache(["printable-content", collage.annotatable], :expires_in => 2.weeks, :compress => H2O_CACHE_COMPRESSION) do %>
      <%= raw collage.printable_content %>
    <% end -%>
  </div>
</div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
if (typeof(export_functions) != 'undefined') {
  export_functions.initiate_collage_data(<%= collage.id %>, {
    data: <%= raw(params[:state] || collage.readable_state || "{}") %>,
    annotations: <%= raw collage.annotations_as_export_json %>,
    layer_data: <%= raw collage.layer_data.to_json %>,
    highlights_only: <%= raw collage.highlights_only.to_json %>,
  });
} else {
  console.warn(' export_functions is undefined. ');
}
});
</script>
<% end -%>

Add undefined check around export_functions.initiate_collage_data
Add undefined check around export_functions.initiate_collage_data
