Webpack + React.lazy + nested routing: Refused to apply style from '*/css/main.css' because its MIME type ('text/html')

Igor

I use React.lazy and nested routing. When I go to /items/any I get this error:

Refused to apply style from 'http://localhost:8000/items/css/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

The problem is in the path, the files are in http://localhost:8000/css/main.css not http://localhost:8000/**items**/css/main.css

How to fix it? I'm not sure, but I think somehow using webpack can fix it.

navigation

import React, { Suspense } from 'react';
import { BrowserRouter, Switch, Route } from 'react-router-dom';
import Loading from '../components/Loading';
// import Item from '../screens/Item'; // working!

const Item = React.lazy(() => import('../screens/Item')); // don't working


const Navigation = () => (
  <BrowserRouter>
    ...
    <Route path="/items/:id">
      <Item />
    </Route>
    ...
  </BrowserRouter>
);

export default Navigation;

webpack.config

module.exports = (env, options) => {
  const isDevMode = options.mode === 'development';
  const dist = path.join(__dirname, 'dist');
  const src = path.join(__dirname, 'src');

  return {
    stats: 'minimal',
    context: src,
    entry: './index.js',
    output: {
      path: dist,
      filename: 'js/[name].js',
      chunkFilename: 'js/[name].js',
    },
    devtool: isDevMode && 'source-map',
    devServer: {
      public: 'http://localhost:8000/',
      publicPath: 'http://localhost:8000/',
      contentBase: './',
      historyApiFallback: true,
      port: 8000,
      overlay: true,
    },
    plugins: [
      new CleanWebpackPlugin(),
      new HtmlPlugin({
        template: 'index.html',
      }),
      new MiniCssExtractPlugin({
        filename: 'css/[name].css',
        chunkFilename: 'css/[name].css',
        ignoreOrder: false, // Enable to remove warnings about conflicting order
      }),
    ],
    ...
  };
};

Igor

I found solution this problem. Just need to add publicPath to output into webpack.config

webpack.config

module.exports = (env, options) => {
  const isDevMode = options.mode === 'development';
  const dist = path.join(__dirname, 'dist');
  const src = path.join(__dirname, 'src');

  return {
    stats: 'minimal',
    context: src,
    entry: './index.js',
    output: {
      path: dist,
      publicPath: isDevMode ? 'http://localhost:8000/' : '', // <-- here
      filename: 'js/[name].js',
      chunkFilename: 'js/[name].js',
    },
    devtool: isDevMode && 'source-map',
    devServer: {
      historyApiFallback: true,
      port: 8000,
      overlay: true,
    },
    plugins: [
      new CleanWebpackPlugin(),
      new HtmlPlugin({
        template: 'index.html',
      }),
      new MiniCssExtractPlugin({
        filename: 'css/[name].css',
        chunkFilename: 'css/[name].css',
        ignoreOrder: false, // Enable to remove warnings about conflicting order
      }),
    ],
    ...
  };

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

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

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

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

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

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

Node/Express - Refused to apply style because its MIME type ('text/html')

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

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

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

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

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

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

Refused to apply style from 'http://localhost:1234/node_modules/primeicons/primeicons.css' because its MIME type ('text/html')

Webpack "Refused to apply style from leaflet.css"

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

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

Refused to apply style from 'http://localhost:3000/style.css' because its MIME type ('text/html')

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

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

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

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

The stylesheet style.css was not loaded because its MIME type, “text/plain”, is not “text/css”

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

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

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

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

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

Refused to display style because MIME type

(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

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive