Search code examples
javascripttypescriptbrowserifytypeerror

Typescript and Browserify - Uncaught TypeError: Cannot read property 'step' of undefined


I have a project right now that basically compiles several typescript files as modules to javascript using commonjs. Then I browserify the entry file which in turn also includes all its modules to a bundle as per the norm.

Well this has been going A-OK until I finally started making more use of Typescript and now I'm getting this weird error during script loading.

Uncaught TypeError: Cannot read property 'step' of undefined

"step" is a particular variable in one of the typescript classes I laid out. And it baffles me as to why I'm getting this error. browserify nor typescript produce any errors and and any attempt at trying to use console.log doesnt work because its almost like this happens during loading and before execution of the code.

The entire project is open source and available here on github https://github.com/wiseguy12851/wiseguy12851.github.io, the website where you can find the problem live is hosted here http://wiseguy12851.github.io/index-dev#/glyph

Any help would be greatly appreciated, thanks in advance


Solution

  • Cannot read property 'step' of undefined This error is thrown on this line : https://github.com/wiseguy12851/wiseguy12851.github.io/blob/a24707ad4cb369ff348a849e3828bc8439b26dac/build/client/scripts/phaser/palette/monoHard.ts#L14

    Source of the error is that game is undefined. Effectively:

    var game;
    game.step; // Uncaught TypeError: Cannot read property 'step' of undefined
    

    Look at the callstack at how MonoHard is initialized and go from there.