Fix traceback due to unavailable module

The class defined in this state references a module that is not
installed. This commit moves the class definition with the try/except
where the deps it requires are loaded.