jmrivas86/django-json-widget

Source map line in jsoneditor.min.js makes collectstatic fail

hnykda opened this issue ยท 11 comments

  • django-json-widget version: 1.1.1
  • Django version: 4.0
  • Python version: 3.8.10
  • Operating System: linux ubuntu (in docker)

Description

When running python manage.py collectstatic with whitenoise 5.3.0, I get the following error:

es/management/commands/collectstatic.py", line 134, in collect
remote:            raise processed
remote:        whitenoise.storage.MissingFileError: The file 'dist/jsoneditor.map' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f260dc431f0>.
remote:        The JS file 'dist/jsoneditor.min.js' references a file which could not be found:
remote:          dist/jsoneditor.map

it seems it's because of the source map bit. When we removed the last line https://github.com/jmrivas86/django-json-widget/blob/master/django_json_widget/static/dist/jsoneditor.min.js#L46 , it works.

I get the same error. For me simply removing the last line, does not resolve the problem. I am still getting the same error

Confirmed - this is blocking our upgrade to Django 4.x. Any progress?

The error we are getting in our build process (which was fine with the same version of this lib but on Django 3.2.x) is:

         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 106, in hashed_name
           raise ValueError(
       ValueError: The file 'dist/jsoneditor.map' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x7f4ca4480f70>.

There is no .map file in the list dir in this repo:

CleanShot 2022-03-15 at 14 12 56@2x

I started deleting the line everytime I am building my docker image now after I went back to Django 3.2.x. It is really frustrating and time consuming. So the solution above seems to work for 3.2.x but not for newer versions. I'm not quite sure why this last line is even in there, if it works without the line.

For typical build systems, deleting a line isn't an option - everything is pulled from the cloud and built in real time, with no human intervention, on many servers at once. Getting a little concerning that no one has responded on this thread. Last commit to the project was a year ago. Is this package still maintained?

Has anyone found a workaround of this issue? I'm facing the same here and because of it I am not able to use this package. I found in SO how to do basic formatting, but that is nothing in comparison to this package,which is pretty good. Maybe someone did a fork with a correction that I did not find?

I actually found a way to deal with this issue, if anyone ever comes here again. He asks for a file which he does not use, so I decided to just put the file where he expects it and it worked like a charm. I am building my project with a Dockerfile, so I just added there

COPY random/jsoneditor.map /usr/local/lib/python3.9/site-packages/django_json_widget/static/dist

the file may be empty. It is not the prettiest solution, but it does work. Hope it helps someone else.

I have the same problem. Already have a native solution?

Another workaround for anyone coming across this issue and using whitenoise is, changing STATICFILES_STORAGE value from whitenoise.storage.CompressedManifestStaticFilesStorage to whitenoise.storage.CompressedStaticFilesStorage

I believe this disables whitenoise file caching, so it you absolutely rely on this for serving static assets this is not a good workaround but if you're just using django admin internally, this is a simple workaround until this library is updated - whitenoise docs on this config

I actually found a way to deal with this issue, if anyone ever comes here again. He asks for a file which he does not use, so I decided to just put the file where he expects it and it worked like a charm. I am building my project with a Dockerfile, so I just added there

COPY random/jsoneditor.map /usr/local/lib/python3.9/site-packages/django_json_widget/static/dist

the file may be empty. It is not the prettiest solution, but it does work. Hope it helps someone else.

It's so terrible, I love it.

Here's a one-liner to do the same thing.

python -c "import django_json_widget as _; from pathlib import Path; p=Path(_.__path__[0]) / 'static' / 'dist' / 'jsoneditor.map'; p.touch()"

This accounts for different package installation paths and whatnot...I use it in CI/CD environment.

Really someone needs to submit a PR to fix this. However, @jmrivas86 hasn't been active on GH in many months and his website doesn't work, so not sure if we can expect a PR to get merged. Failing that someone will have to fork...

While waiting for #70 to be merged, you can avoid this exception globally by using a custom STATICFILES_STORAGE:

from django.contrib.staticfiles.storage import ManifestStaticFilesStorage


class ManifestStaticFilesStorageNotStrict(ManifestStaticFilesStorage):
    
    def hashed_name(self, name, content=None, filename=None):
        try:
            return super().hashed_name(name, content=content, filename=filename)
        except ValueError:
            return name

Fixed in #70