This is because the element hadn't been loaded at the time when the bundle js was being executed.
I'd move the <script src="sample.js" type="text/javascript"></script>
to the very bottom of the index.html
file. This way you can ensure script is executed after all the html elements have been parsed and rendered .