You can add a condition to only run the script on the pages that have the necessary HTML tags. check for the existence of a specific element on the page and only run the script if that element is present.
if (document.getElementById('navigation-menu')) {
import ('./template.js');
}
This way, the script would only run if the element with the ID 'navigation-menu' is present on the page, ensuring that it won't break on the login page.