HACS disapeared, cannot remove it, cannot add it again

Hello
Today, after need of host restart, I found whole Lovelace broke apart with red messages that custom cards cannot be found.
Dev tools show a lot of messages like Loading module from “http://192.168.0.165:8123/hacsfiles/lovelace-multiple-entity-row/multiple-entity-row.js” was blocked because of a disallowed MIME type (“text/plain”).
Further googlying point me to HACS which indeed is missing from left menu.
It is present in integrations but there is a red exlamation mark next to its sensor:

Attempt of removing this integration end up with http 500 error

Attempt of addinng HACS again, ends with lord of the rings rolling to infinity:


Found nothing in logs
Is there any way to recorver from this situation? I’ve read some posts about removing .storage files but without detail enabling me to understand what am I doing. If components installed under hacs will remain etc.
I appreciate any help incl information what has really happened.

This is what I found in logs after switching them to debug:

2020-12-06 21:14:37 ERROR (MainThread) [homeassistant.bootstrap] Error setting up integration hacs - received exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 64, in async_setup_component
    return await task  # type: ignore
  File "/usr/src/homeassistant/homeassistant/setup.py", line 158, in _async_setup_component
    await async_process_deps_reqs(hass, config, integration)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 343, in async_process_deps_reqs
    await requirements.async_get_integration_with_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 74, in async_get_integration_with_requirements
    await async_process_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 121, in async_process_requirements
    if pkg_util.is_installed(req):
  File "/usr/src/homeassistant/homeassistant/util/package.py", line 54, in is_installed
    return version(req.project_name) in req
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3125, in __contains__
    return self.specifier.contains(item, prereleases=True)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/specifiers.py", line 789, in contains
    item = parse(item)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py", line 56, in parse
    return Version(version)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py", line 275, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

HA restord from backup - didn’t help.
HACS completely removed from HA. Including its files from .storage as well as entries found in core.device_registry and core.config_entries. Whole host restarted.
Copied hacs files to filesystem.
HA restarted.
Attemted to add hacs integration. Just after selecting HACS, the list refreshed showing all available integrations again. At the same time simmilar log reported above appeared in core logs.

2020-12-07 00:23:09 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 136, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 69, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 117, in async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 530, in async_create_flow
    await async_process_deps_reqs(self.hass, self._hass_config, integration)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 343, in async_process_deps_reqs
    await requirements.async_get_integration_with_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 74, in async_get_integration_with_requirements
    await async_process_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 121, in async_process_requirements
    if pkg_util.is_installed(req):
  File "/usr/src/homeassistant/homeassistant/util/package.py", line 54, in is_installed
    return version(req.project_name) in req
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3125, in __contains__
    return self.specifier.contains(item, prereleases=True)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/specifiers.py", line 789, in contains
    item = parse(item)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py", line 56, in parse
    return Version(version)
  File "/usr/local/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py", line 275, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

Finding hacs again and selecting it ended with bussy circle (see pictures above) and the process never ended

I’m really desperate right now.

I’d recommend a backup (config only) and a fresh install. Probably a Python library is broken.

Yeah… I’m afraid it’s the only way out.
If I new it yesterday I would save a lot of hours of work. But I believed that it be fixed rather than reinstalled.
BTW how can python library broke? Isn’t really a way to fix it other than clean install?

What do you mean by “config only”
Here is backup configuration and respective restore configuration:

Which item should I avoid to restore?
Performing clean install I probably will go for HA0.118 anyway so HA will be excluded from restore.

thank you.

Make a partial backup with only your HA config, and then restore it on a plain install. You might want to include SSL if you use it too.

And what about all add-ons?
Are you suggesting that backing them up can transfer the broken python lib to the new instance?

Well probably not, I’m just suggesting the most bare-bones way possible.

actually i had the same issue, i only can’t remember exactly how i resolved it…
This rings some bell and it makes sense

In an act of desperation I decided to do one more thing before installing HA from scretch: I updated HA to most recent version (from 0.117.6 to 0.118.5).

After that I attempted to add HACS which this time finished with success!

I don’t know what was happening. Something broken in HA system fixed by update? how it broke on its own?
Or maybe broken remote HACS repo providing wrong data (unparsable version number?) fixed in the meantime? Just quessing possible reasons.

Thank you guys for willing to help. Sad that no developer gave helping hand - I assume they know the best what is happening. Other users may guess only. Because it’s not the first time devs are mute in case of serious problem, maybe it’s wrong place to ask? Is there some other place when a user can get help from more qualified persons?
If you say GIT hub, I failed to get help using this channel too (it was supervisor crash pretty famous almost half a year ago). GITHub is good for reporting issues. not for for operational help.

Another question which I could ask is why some JS modules installed by HACS cannot work without HACS? It’s just the JS script. There are other HACS components (custom components) which can work without hacs. But not JS scripts. Paradoxically the latter can work if are cached by browser then can work forever. But often are shown for the first seconds to be replaced by error message after a while. Really don’t get this idea. it all makes the system less reliable with a lot of points of failure.

None of that is true. I’d wager that your resource pointers are incorrect when you attempt to use the resource without hacs.

Hmm. I believe most of them are added by HACS itself. Some might be manually moved from yaml to resources when it was required since some HA version (I think some time back at beginning of this year).
Here is how those looks like. Can you point me to what might be wrong with them?

You’re using hacsfiles.

When hac’s is gone, you can no longer use the hacs provided resource link because it no longer exists.

I.e. if you’re using /hacsfiles/..., you have to change it to whatever the path to the files are.

Example: Home assistant by default has a mapped directory named /local that maps to /config/www.

/hacsfiles is another map. When you remove HACS, that map no longer exists.

The only reason custom_components still work is because they are always located in config/custom_components and there is no map that’s used by the backend to access that location.

1 Like

Got it.
But for some reason the decision has been made to locate js modules installed by HACS in directory which is not available without HACS running. I’m sure there was some motivation behind it. but once HACS fails to start, whole GUI might break apart.
Just thinking loud: what would be the difference installing HACS JS modules in /config/www?

That’s not true. The folder is available. The MAP to it is not.

The path is different. That’s it.

Instead of using /hacsfiles use the absolute path without the map. If I had my access to my files currently, I would write the real path out for you but I don’t. Either way, change all your resources from /hacsfiles/... to /local/<cantrememmberfoldername>/... and everythign will work regardless of hacs running or not.

Understand. Very helpful. Thank you
Still wondering why it’s not done this way by default. Security?

I’m not sure what you mean? The map only exists because people had so many issues with /local equaling /config/www so the dev for hacs just made a map so they didn’t have to understand that.

If you ‘think’ in terms of Microsoft windows, /local is a shortcut folder on your desktop to a folder inside your system somewhere. /hacsfiles is the same thing but HACS creates the shortcut on your desktop. Without HACS, that shortcut isn’t created.

So, when hacs is starting it adds mapping to hacsfiles directory which exists until next restart?

I understand the idea to have separate folder for files installed by hacs. A bit lost with this local vs /config/www. Why forget about local and use config/www only? Maybe because of differences in ways how HA can be deployed?

Isn’t possible to map hacsfiles permamently to be accessible for http server (without HACS)? maybe kind of soft link on filesystem level to www directory?