I got the same error because I had accidentally used <div> instead of <canvas> as the element on which I attempt to call getContext.
I got the same error because I had accidentally used <div> instead of <canvas> as the element on which I attempt to call getContext.