JavaScript Error: Uncaught TypeError: Cannot read property ‘addEventListener’ – Solved!

JavaScript Event Listener Error: Cannot Read Property ‘addEventListener’

I’m working on building some JavaScript event listeners for a project.

While working on a demo based on this YouTube Video. I got an error that took me a couple of minutes to figure out.

I encountered this error, JavaScript Event Listener Error: Cannot Read Property ‘addEventListener’, while working through this video on creating JavaScript Event Listeners.

If you follow this video and have issues getting your JavaScript Event Listener to work then read on to my solution below to see how I fix my below.

JavaScript Event Listener Example Video

The JavaScript Code to Add an EventListener

const grandparent = document.querySelector(".grandparent")

const parent = document.querySelector(".parent")

const child = document.querySelector(".child")

 grandparent.addEventListener('click', e => {

    console.log(e)
     }) 
 

JavaScript Uncaught TypeError: Cannot read property ‘addEventListener’ of

Solution: Move JavaScript to End of File

The root cause of the error is that if we load the JavaScript file before the DOM element loads then the const reference to grandparent class fails as it has not yet been loaded in to the DOM as the web page is rendering.

By simply moving the JavaScript tag to the end of the web page, it now loads after the div tag elements in the DOM so they can be referenced in the JavaScript and available in memory.

I hope this makes sense and that it helps somebody! 🙂

~Cyber Abyss

Subversion (SVN) error: E120106: ra_serf: The server sent a truncated HTTP response body – Automate the command line workaround with VBScript

SVN error: ra_serf: The server sent a truncated HTTP response body.

While working on a large enterprise project, I’m getting a Subversion (SVN) error “SVN error: ra_serf: The server sent a truncated HTTP response body.” when updating a repository to a network drive.

I found part of the answer on a Stack Overflow post about SVN error: E120106: ra_serf: The server sent a truncated HTTP response body.

This work around assumes the SVN checkout folder is already present provided was a two SVN command line commands.

$ svn cleanup
$ svn up

I ran the SVN command line commands manually for days but still the huge project updates would hang after about 5-10 minutes.

I decided I would try to automate this process a little bit to see if I could run the commands via a script and just repeat the cleanup and update commands every time it hung or stopped until the Subversion (SVN) update process has successfully completed.

Automating the SVN Cleanup and Update Commands in a VBScript.

Below is the script I just wrote today to try and automate the SVN processes.

  • Create Windows Shell
  • Use Shell and Run method calling taskkill command to kill any SVN processes that might be hung.
  • Use Shell and Run SVN with the “cleanup” w/ path argument to identify the SVN Repository folder we are targeting.
  • Use Shell and Run SVN with the update command, “up”, with path to identify the SVN Repository folder we are targeting.

The VBScript Code

Dim oShell : Set Oshell = CreateObject("WScript.Shell")

For i = 1 to 3
    OShell.Run "taskkill /im svn.exe /F", 5, True
    OShell.Run """C:\Program Files\VisualSVN Server\bin\svn.exe"" cleanup H:\Repo\", 1, True
    OShell.Run """C:\Program Files\VisualSVN Server\bin\svn.exe"" up H:\Repo\", 1, True
Next
Set OShell = Nothing

SVN Error: E120106 in a Nutshell

In summary, the SVN error E120106 for truncated HTTP response body is coming from the SVN server.

Everyone on this team has this issue and checkout code repository to their local C drives to checkout and commit work.

I suspect our network is just slow enough to cause a hiccup in communications between HTTP on SVN repository side and Windows file system.

I hope this work around and simple explanation help somebody out there with the same issue. 🙂

~Cyber Abyss