13

while building a debug toolbar in Django I am getting an error in file toolbar.js ie. s.map: HTTP error: status code 404, net:: ERR_UNKNOWN_URL_SCHEME toolbar.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.

can anyone tell me the possible fix for that?

Nkgupta
  • 144
  • 1
  • 6
  • Do you use Django Debug Toolbar or build your own solution? – Dmitry Belaventsev Sep 22 '20 at 16:29
  • I used Django Debug Toolbar and try to build a Django debugger by taking references from some articles, documentation, and video tutorial. – Nkgupta Sep 22 '20 at 17:46
  • Ok, in the meantime we need more information to help you. Is that toolbar.js file was created by you or it's the part of DDT (django debug toolbar)? Also, we should take a look on your template where you add that file. Please add the required information to your question. – Dmitry Belaventsev Sep 22 '20 at 18:39

6 Answers6

27

I found solution here How to set content type of JavaScript files in Django

#settings.py
if DEBUG:
    import mimetypes
    mimetypes.add_type("application/javascript", ".js", True)
drewslee
  • 371
  • 2
  • 3
  • 2
    This works but surprisingly, I removed then these lines and it's still working. There's something about it that I don't understand.. Maybe it's the browser's cache ? – Benbb96 Jan 21 '21 at 13:59
  • 1
    if it doesn't work with this line you have 3 choices : remove cache , change server port or browser – kadiro Dec 20 '21 at 12:01
19

Expanding on drewslee answer

The solution to the problem is indicated in the documentation

  • For Windows, you need to edit the registry. Set HKEY_CLASSES_ROOT\.js\Content Type to text/javascript.
AlexElizard
  • 785
  • 4
  • 17
  • 1
    I made the change then rebooted but it's still not working and showing me the same error in console. – Benbb96 Jan 21 '21 at 13:54
  • 1
    did you replace the value as shown in the [picture](https://i.stack.imgur.com/DLBOS.png)? – AlexElizard Jan 22 '21 at 00:28
  • Yes I did exactly the same. Then I tried the solution from drewslee and it was working. But I stated in my other comment that it was still working after removing his solution, so maybe the registry edit was working after all. I just don't know ^^ Thanks anyway for your help ! – Benbb96 Jan 22 '21 at 10:12
  • You need to restart your computer for the changes to take effect – AlexElizard Jan 24 '21 at 05:37
  • 1
    I *didn't* need to restart my computer after editing the registry, just the Django webserver. Then it worked – Reversed Engineer Feb 07 '21 at 15:10
  • 6
    Today I ran into the same issue again and I made the reg edit then restarted the Django webserver but it was still not working. I tried restarting PyCharm, still not working. Finally I had the idea to clear my browser's cache and then it was all good ! – Benbb96 Feb 10 '21 at 14:20
  • @Benbb96 you are right, [the official documentation](https://django-debug-toolbar.readthedocs.io/en/latest/tips.html) recommends the same thing: `Browsers have become more aggressive with caching static assets, such as JavaScript and CSS files. Check your browser’s development console, and if you see errors, try a hard browser refresh or clearing your cache`. – Arislan Makhmudov Nov 12 '21 at 04:45
6

I have faced the problem and it was fixed after edit the Windows registry. I just Set HKEY_CLASSES_ROOT.js\Content Type from text/plain to text/javascript.

Now the problem is solved!

Sumon Ahmed
  • 61
  • 1
  • 4
2

I faced the same error. It was resolved once I updated the HKEY_CLASSES_ROOT.js\Content Type from text/plain to text/javascript in my Windows using RegistryEditor.

After that I had to refresh my browser cache to be able to see the toolbar

lejlun
  • 4,140
  • 2
  • 15
  • 31
1

Clear your browsers Cache

If you configured the settings.py and the urls.py as the documentation page implies... Just go to your browser clear the data section right under the privacy policy and clear your browser's cache.

That works for me :)

Zenonymous
  • 149
  • 2
  • 4
0

In my case, i try running it on another server like 8080 and it works

Manh Pham
  • 1
  • 1