bob
bob

Reputation: 933

webpack dev server not running

I'm creating a webpack config. I've installed the devserver module, and have configured it to run on port 9000 while webpack watches for file changes.

Currently when I run npx webpack, the command prompt doesn't return, so I assume that webpack is watching. However, if I visit http://localhost:9000, my browser basically shrugs at me. "This site can't be reached"

If I check for activity on the port using:

netstat -tunlp | grep 9000

... nothing gets returned. Nothing is listening on that port number.

This is my config:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require ('path');

module.exports = {

    mode : 'development',
    
    entry: './src/index.js',

    watch: true,

    output : {
    filename : 'main.js',
    path :         path.resolve(__dirname, 'dist'),
    clean: true
    },

    devtool : 'inline-source-map',

    devServer : {
    static : './dist',
    logging : 'info',
    overlay :  true,
    port : 9000
    },
    
    plugins: [

    new HtmlWebpackPlugin({
        title : 'Development'
    })
    
    ]
    
};

Upvotes: 2

Views: 4396

Answers (1)

Oleksandr Oliynyk
Oleksandr Oliynyk

Reputation: 876

I had similar issue today, very frustrating. I was trying to start webpack dev sever with a similar config file. And it wasn't working.

I had to change the start command to make it work and get rid of watch: true in the config file.

in the package.json file

  "scripts": {
    NOT WORKING:
    "start": "webpack --config webpack.dev.js",
    
    WORKING:
    "start": "webpack serve --config webpack.dev.js",
  }

Cheers,

Upvotes: 3

Related Questions