Hmm...I arrived at that by getting the same error when adding an img to the div used by the mapview container.
The most common reason for this error would be that the div doesn't exist in the DOM at the time you're trying to access it. What do you get if you place the code below before the MapView constructor?
console.log(document.getElementById("viewDiv") == null);
If it says "true" then that's the issue, in which case I would recommend moving the script tag that starts up your application to a place lower in the document (perhaps right before the closing body tag).