Refused to execute *path_to_bundle* as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type

Denis Lenskiy

I'm developing web app using Django as a backend and Vue js as a frontend. I connected them via webpack. When I develop app in Dev mode, everything is good, I don't use chunks, which are created using npm run build. But when it comes to Stage or Prod mode, when DEBUG=False on Django, and npm run build on vue js, to build all static files, I got error

Refused to execute http://localhost:8000/static/sections_dist/js/chunk-common.34112dfe.js as script because "X-Content-Type: nosniff" was given and its Content-Type is not a script MIME type.

Did not parse stylesheet at 'http://localhost:8000/static/sections_dist/css/chunk-common.677f6644.css' because non CSS MIME types are not allowed in strict mode.

maybe I'm using incorrect webpack settings, please help me with that...

My webpack.config.js:

const BundleTracker = require("webpack-bundle-tracker")
const path = require('path')

module.exports = {
  publicPath: "/static/sections_dist/",
  outputDir: '../project/static/sections_dist/',
  chainWebpack: config => {

    // config.optimization
    //   .splitChunks(false)

    config
      .plugin('BundleTracker')
      .use(BundleTracker, [{filename: '../frontend/webpack-stats.json'}])
    config.devServer
      .public('http://0.0.0.0:8000')
      .host('0.0.0.0')
      .port(8080)
      .hotOnly(true)
      .watchOptions({poll: 1000})
      .https(false)
      .headers({
        'Access-Control-Allow-Origin': ['*']
      })
  }
}

my base.html body, where I render bundles:

<body>
      <div id="app">

      </div>

      {% if not settings.DEBUG %}
        {% render_bundle 'chunk-common' 'js' 'SECTIONS' %}
        {% render_bundle 'chunk-vendors' 'js' 'SECTIONS' %}
        {% render_bundle 'chunk-vendors' 'css' 'SECTIONS' %}
        {% render_bundle 'chunk-common' 'css' 'SECTIONS' %}
      {% endif %}

      {% block js_application %}
      {% endblock %}
    </body>

and html file for rendering src in frontend, which is inheriting from that base.html:

{% load render_bundle from webpack_loader %}

{% block js_application %}
  {% render_bundle 'anonymous' 'js' 'SECTIONS' %}
  {% render_bundle 'anonymous' 'css' 'SECTIONS' %}
{% endblock %}

Denis Lenskiy

So after several hours I found out what went wrong.

I had an invalid paths of static files in django configuration. After debugging and changing urls from

path('static/<str:path>/', serve,
         {'document_root': settings.STATIC_ROOT}),
    path('media/<str:path>/', serve,
         {'document_root': settings.MEDIA_ROOT}),

to

re_path(r'^static/(?P<path>.*)$', serve,
            {'document_root': settings.STATIC_ROOT}),
    re_path(r'^media/(?P<path>.*)$', serve,
            {'document_root': settings.MEDIA_ROOT}),

everything got worked

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to address error "Did not load script at 'script name' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given

From Dev

Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

From Dev

Refused to execute script from '*' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

From Dev

Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable

From Dev

Importing jQuery plugin into Angular 2+ Refused to execute script because its MIME type ('text/html') is not executable

From Dev

Refused to execute script from '*.ts' because its MIME type ('video/vnd.dlna.mpeg-tts') is not executable

From Dev

Refused to execute script from 'url' because its MIME type ('image/jpeg') is not executable

From Dev

Refused to execute script because strict MIME type checking is enabled

From Dev

Refused to execute script from URL because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

From Dev

Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

From Dev

Tensorboard is showing a blank page (Refused to execute script from 'http://localhost:6006/index.js' because its MIME type)

From Dev

Rewrite requests from loopback to angular2 (Refused to execute script because its MIME type ('text/html') is not executable)

From Dev

Chrome and Spring security: Refused to execute script from 'http://<server url>/assets/app.js' because its MIME type ('') is not executable

From Dev

Refused to execute script from '..../angular.min.js' because its MIME type ('application/octet_stream') is not executable, and strict MIME type check

From Javascript

Refused to execute script, strict MIME type checking is enabled?

From Dev

Error on minification in console "Refused to execute because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled"

From Dev

Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type

From Dev

Clicking on a MIME type execute a script to open file

From Dev

Node refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME

From Dev

content is not loading because its MIME type, "text/html" is not "text/css"

From Dev

Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to apply style because its MIME type "text/html" is not supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to apply style from 'URL' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to apply style from [Link] because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

"Refused to apply style from because its MIME type "('font/woff2')" is not a supported stylesheet MIME type, and strict MIME checking is enabled"

From Dev

(Node Express)Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

From Dev

Refused to display style because MIME type

From Dev

Failed to load module script because of a disallowed MIME type

From Dev

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".?

Related Related

  1. 1

    How to address error "Did not load script at 'script name' because non script MIME types are not allowed when 'X-Content-Type: nosniff' is given

  2. 2

    Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

  3. 3

    Refused to execute script from '*' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

  4. 4

    Webpack dev server throws error - Refused to execute script because its MIME type ('text/html') is not executable

  5. 5

    Importing jQuery plugin into Angular 2+ Refused to execute script because its MIME type ('text/html') is not executable

  6. 6

    Refused to execute script from '*.ts' because its MIME type ('video/vnd.dlna.mpeg-tts') is not executable

  7. 7

    Refused to execute script from 'url' because its MIME type ('image/jpeg') is not executable

  8. 8

    Refused to execute script because strict MIME type checking is enabled

  9. 9

    Refused to execute script from URL because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled

  10. 10

    Refused to execute script from 'file_name.php' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

  11. 11

    Tensorboard is showing a blank page (Refused to execute script from 'http://localhost:6006/index.js' because its MIME type)

  12. 12

    Rewrite requests from loopback to angular2 (Refused to execute script because its MIME type ('text/html') is not executable)

  13. 13

    Chrome and Spring security: Refused to execute script from 'http://<server url>/assets/app.js' because its MIME type ('') is not executable

  14. 14

    Refused to execute script from '..../angular.min.js' because its MIME type ('application/octet_stream') is not executable, and strict MIME type check

  15. 15

    Refused to execute script, strict MIME type checking is enabled?

  16. 16

    Error on minification in console "Refused to execute because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled"

  17. 17

    Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type

  18. 18

    Clicking on a MIME type execute a script to open file

  19. 19

    Node refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME

  20. 20

    content is not loading because its MIME type, "text/html" is not "text/css"

  21. 21

    Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  22. 22

    Refused to apply style because its MIME type "text/html" is not supported stylesheet MIME type, and strict MIME checking is enabled

  23. 23

    Refused to apply style from 'URL' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  24. 24

    Refused to apply style from [Link] because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  25. 25

    "Refused to apply style from because its MIME type "('font/woff2')" is not a supported stylesheet MIME type, and strict MIME checking is enabled"

  26. 26

    (Node Express)Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled

  27. 27

    Refused to display style because MIME type

  28. 28

    Failed to load module script because of a disallowed MIME type

  29. 29

    Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".?

HotTag

Archive