Chetan
Chetan

Reputation: 1151

bundle.js not found , getting 404 on browser

Not able to find the bundle.js file. Getting the 404 error , /dist/bundle.js not found on browser.But there is dist directory present and I can see the bundle.js file inside it.What could be the problem , given is my webpack.config.js file.

const path = require("path");
const webpack = require("webpack");
const bundlePath = path.resolve(__dirname, "/dist/");

module.exports = {
  entry: "./src/index.js",
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        options: { presets: ['env'] }
      },
      {
        test: /\.css$/,
        use: [ 'style-loader', 'css-loader' ]
      }
    ]
  },
  resolve: { extensions: ['*', '.js', '.jsx'] },
  output: {
    publicPath: bundlePath,
    filename: "bundle.js"
  },
  devServer: {
    contentBase: path.join(__dirname,'public'),
    port: 3000
  },
  plugins: [ new webpack.HotModuleReplacementPlugin() ]
};

Upvotes: 1

Views: 534

Answers (1)

ChrisR
ChrisR

Reputation: 4008

It's because the server is served from /public/ (via contentBase property).

You need to remove contentBase so the scripts will be loaded from bundlePath by default.

Upvotes: 1

Related Questions