简体   繁体   中英

debugging webpack config with react

I get running into several errors every time I try to start my application. I would really love some help debugging this.

These are my errors::

Refused to execute script from ' http://127.0.0.1:8080/scripts/bundle.js ' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

GET http://127.0.0.1:8080/scripts/bundle.js net::ERR_ABORTED 404 (Not Found)

Here is my webpack config file:

var path = require('path');

module.exports = [
    {
      entry: './assets/stylesheets/app.scss',
      output: {
        // This is necessary for webpack to compile
        // But we never use style-bundle.js
        path: path.join(__dirname, 'public/scripts'),
        filename: 'style-bundle.js',
      },      
      devServer: {
        contentBase: "./public",
        hot: true
      },
      module: {
        rules: [{
          test: /\.scss$/,
          use: [
            {
              loader: 'file-loader',
              options: {
                name: 'bundle.css',
              },
            },
            { loader: 'extract-loader' },
            { loader: 'css-loader' },
            {
              loader: 'sass-loader',
              options: {
                includePaths: ['./node_modules'],
              }
            },
          ]
        }]
      },
    },
    {
      entry: "./src/app.js",
      output: {
        path: path.join(__dirname, 'public/scripts'),
        filename: "bundle.js"
      },
      devServer: {
        contentBase: "./public",
        hot: true
      },
      module: {
        loaders: [{
          test: /\.js$/,
          loader: 'babel-loader',
          query: {
            presets: ['env','react']
          }
        }]
      },
    }
  ];

Is there anything that I am missing????

I'm able to simulate the same 404 Error with a different config. Long story short:

  • did you run webpack-dev-server?
  • is your package.json OK?
  • is the related html file (index.html) OK? Mind the script tag with bundle.js and the path
  • check and fix the contentBase with devServer at webpack.config.js
  • module.exports - you only need the devServer once.

Example: devServer: { contentBase: path.join(__dirname, 'public/scripts'), hot: true },

The contentBase has to have a full path like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM