diff --git a/app/assets/javascripts/discourse/components/image-uploader.js.es6 b/app/assets/javascripts/discourse/components/image-uploader.js.es6 index 8ed486ade90..5d468b15e6e 100644 --- a/app/assets/javascripts/discourse/components/image-uploader.js.es6 +++ b/app/assets/javascripts/discourse/components/image-uploader.js.es6 @@ -15,7 +15,10 @@ export default Ember.Component.extend(UploadMixin, { willDestroyElement() { this._super(...arguments); - $("a.lightbox").magnificPopup("close"); + const elem = $("a.lightbox"); + if (elem && typeof elem.magnificPopup === "function") { + $("a.lightbox").magnificPopup("close"); + } }, @computed("imageUrl")