Javascript does not work when signed in or when comments are open This is my info.yml file.

name: tnt
description: Drupal 8 starter theme
type: theme
core: 8.x

libraries:
  - tnt/global-styling

regions:
  header: 'Header'
  primary_menu: 'Primary menu'
  breadcrumb: 'Breadcrumb'
  content: 'Content'
  sidebar_first: 'Sidebar first'
  footer_first: 'Footer first'


This is my libraries.yml file.

global-styling:
  version: VERSION
  css:
    theme:
      styles/style1.css: {}
  js:
    js/js1.js: {}
  dependencies:
   - core/jquery


This is my JavaScript file.

$(document).ready(function() {

  alert("Here I am");   

});// end ready


This works fine unless one of these conditions is true.


User is signed in
User is on a page where comments are open


Obviously, I had much more complicated JavaScript code, but I reduced it to something simpler to illustrate the point.

I am currently using Drupal 8.1.10.

How do I get this to work when users are signed in and/or comments are open?

What am I doing wrong?
To get the jquery alias $ working in drupal, you have map it like this:

(function ($) {
  $(document).ready(function() {
    alert("Here I am");   
  });
})(jQuery);


The document ready function is not the best option, better use Drupal.behaviors and once():

https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview