EmilStenstrom / django-components

Create simple reusable template components in Django.
MIT License
1.19k stars 76 forks source link

Incompatiblity with django-webpack and ManifestStaticFilesStorage ? #753

Open stuaxo opened 1 week ago

stuaxo commented 1 week ago

I'm trying to add django-components to a project that has webpack-loader and uses ManifestStaticFilesStorage.

When I add ComoonentsFileSystemFinder, then collectstatic stops working

STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    # Django components
    #"django_components.finders.ComponentsFileSystemFinder"
]

I'm trying to add django-components to a project that has webpack-loader and uses ManifestStaticFilesStorage (this is part of the default settings for wagtail).

When I add ComoonentsFileSystemFinder, then collectstatic stops working

STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    # Django components
    #"django_components.finders.ComponentsFileSystemFinder"
]
$ python manage.py collectstatic

Post-processing 'optimiser.css' failed!

Traceback (most recent call last):
  File "~/projects/work/co/project/jao-web/src/manage.py", line 29, in <module>
    main()
  File "~/projects/work/co/project/jao-web/src/manage.py", line 25, in main
    execute_from_command_line(sys.argv)
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
    collected = self.collect()
                ^^^^^^^^^^^^^^
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 154, in collect
    raise processed
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/storage.py", line 372, in _post_process
    content = pattern.sub(converter, content)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/storage.py", line 249, in converter
    hashed_url = self._url(
                 ^^^^^^^^^^
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/storage.py", line 182, in _url
    hashed_name = hashed_name_func(*args)
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/storage.py", line 422, in _stored_name
    cache_name = self.clean_name(self.hashed_name(name))
                                 ^^^^^^^^^^^^^^^^^^^^^^
  File "~/.virtualenvs/project-py311/lib/python3.11/site-packages/django/contrib/staticfiles/storage.py", line 143, in hashed_name
    raise ValueError(
ValueError: The file 'optimiser.css.map' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x1071e15d0>.
JuroOravec commented 1 week ago

Hi @stuaxo, thanks for reporting! Could you create and share a minimal project to reproduce this? I haven't used webpack-loader / Wagtail, and I don't think @EmilStenstrom has either.

Could you give me pointers on how the setup works?

  1. Do you know where the optimiser.css is coming from? Is it something that you defined, or generated by wagtail? I assume that the optimiser.css.map file that's generated by webpack? And where is the file placed, is it in the static dir?

  2. How does the integration with webpack work? Is webpack build step triggered as a separate command before calling collectstatic, or does it run during collectstatic?