Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 4.0 File Not Found Error #761

Closed
aibharata opened this issue Dec 17, 2021 · 17 comments
Closed

Django 4.0 File Not Found Error #761

aibharata opened this issue Dec 17, 2021 · 17 comments

Comments

@aibharata
Copy link

aibharata commented Dec 17, 2021

I'm trying to run drf-yasg with Django 4.0 and Whitenoise.
I keep getting file not found errors shown below when I run python manage.py collectstatic. Any suggestions how to solve this?

whitenoise.storage.MissingFileError: The file 'drf-yasg/redoc-old/redoc.min.map' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object 

The JS file 'drf-yasg/redoc-old/redoc.min.js' references a file which could not be found:
 drf-yasg/redoc-old/redoc.min.map
@m-nagy
Copy link

m-nagy commented Dec 18, 2021

Try to change the storage to
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
If it works, then it is a whitenoise related issue, better to report it on their repo.

@aibharata
Copy link
Author

whitenoise.storage.CompressedStaticFilesStorage

That also didn`t work. I had used the below settings with drf-yasg, Python37, and Django 3+ versions without any problems for a long time.

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

Seems like redoc.min.map is not generated in Django 4.0 version.

diogosilva30 added a commit to diogosilva30/OpenNews that referenced this issue Dec 22, 2021
@diogosilva30
Copy link

Also facing the same problem:

django==3.2.8
whitenoise==5.3.0
drf-yasg==1.20.0

@dalokdaga
Copy link

Gracias @m-nagy funciono para django 4.0

@diogosilva30
Copy link

@dalokdaga upgrading to django 4.0 did not work for me.
Can you share the exact versions you are using (django, whitenoise, drf-yasg)?

@dalokdaga
Copy link

@spamz23 my config is this, i hope you have luck....

-----requirements------
Django==4.0
whitenoise==5.3.0
drf-yasg==1.20.0

--------settings--------

MIDDLEWARE = [
...
'whitenoise.middleware.WhiteNoiseMiddleware',
]

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'

@egism
Copy link

egism commented Dec 28, 2021

Having the same issue with django 4 but without whitenoise. Worked well with django 3.

@vlinhart
Copy link

vlinhart commented Jan 3, 2022

https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#manifeststaticfilesstorage is why it's broken, js map file is searched for.

 File "/envs/roomstorm/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 97, in hashed_name
    raise ValueError("The file '%s' could not be found with %r." % (filename, self))
ValueError: The file 'drf-yasg/redoc-old/redoc.min.map' could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x7f892c50de50>.

@pandafy
Copy link
Contributor

pandafy commented Jan 17, 2022

Check this ticket in Django: https://code.djangoproject.com/ticket/33353. A work-around is to update static files storage backend

class NoSourceMapsStorage(ManifestStaticFilesStorage):
    patterns = (
        (
            "*.css",
            (
                "(?P<matched>url\\(['\"]{0,1}\\s*(?P<url>.*?)[\"']{0,1}\\))",
                (
                    "(?P<matched>@import\\s*[\"']\\s*(?P<url>.*?)[\"'])",
                    '@import url("%(url)s")',
                ),
            ),
        ),
    )

@pandafy
Copy link
Contributor

pandafy commented Jan 17, 2022

Also check d9700db#r64030387

@torhovland
Copy link

Changing whitenoise.storage.CompressedManifestStaticFilesStorage to whitenoise.storage.CompressedStaticFilesStorage as suggested by @dalokdaga worked for me.

@PetrDlouhy
Copy link
Contributor

PetrDlouhy commented Feb 22, 2022

If I install from source on master branch (with pip install git+https://github.com/axnsan12/drf-yasg#egg=drf-yasg), the collectstatic almost works, except there is one small mistake left, which I fixed in #778

@3h04m1
Copy link

3h04m1 commented Apr 19, 2022

It happens with Node.js scripts

I had the same problem, don't know if it;s still actual, but found the solution for me.
The problem was in the min.js files , django cacheing seems to find trouble with this kind of files.
So I ended with 2 solutions:

  1. If you use some npm js with all it's imports and features try to use django-compressor django-compressor-toolkit see Using Node.js With Django
  2. Try to use a cdn instead, or if is a Github repo, try https://raw.githubusercontent.com/[user]/[repo]/[file]

Hope this will help you, please react if helps it's useful to know if I'm right

@wmorrell
Copy link

This is caused by Django 4.0+ updating its staticfiles collection to also modify source map comments to "mangled" urls that include content hashes in the filename. The files distributed by current latest drf-yasg (1.20.0) includes scripts with source map comments, but does not include the source maps themselves. A quick work-around for Django 4.0 with continuing to use one of the Manifest staticfiles storage classes, is to simply add empty files for the map files in one of your static directories. For drf-yasg, the missing files are:

drf-yasg/redoc-old/redoc.min.map
drf-yasg/redoc/redoc.standalone.js.map
drf-yasg/swagger-ui-dist/swagger-ui-bundle.js.map
drf-yasg/swagger-ui-dist/swagger-ui-es-bundle-core.js.map
drf-yasg/swagger-ui-dist/swagger-ui-es-bundle.js.map
drf-yasg/swagger-ui-dist/swagger-ui-standalone-preset.js.map

Because the collectstatic command looks in all the static folders configured, it doesn't matter if these are included in the upstream package, as long as they are included somewhere. The next release should be sure to either include dist static files without these source map comments, or keep the comments and also distribute the *.map files (or, do both).

@Jay-davisphem
Copy link

changing the STATICFILES_STORAGE from whitenoise.storage.CompressedManifestStaticFilesStorage to whitenoise.storage.CompressedStaticFilesStorage works for me.

@pandafy
Copy link
Contributor

pandafy commented Jul 15, 2022

Can this be closed now, since #778 is merged?

@JoelLefkowitz
Copy link
Collaborator

@pandafy absolutely, thanks for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests